summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/Avatar.php2
-rw-r--r--classes/Config.php4
-rw-r--r--classes/Fave.php2
-rw-r--r--classes/File.php33
-rw-r--r--classes/File_to_post.php2
-rw-r--r--classes/Group_block.php2
-rw-r--r--classes/Group_inbox.php2
-rw-r--r--classes/Group_member.php39
-rw-r--r--classes/Inbox.php163
-rw-r--r--classes/Login_token.php27
-rw-r--r--classes/Memcached_DataObject.php31
-rw-r--r--classes/Notice.php189
-rw-r--r--classes/Notice_inbox.php130
-rw-r--r--classes/Notice_tag.php2
-rw-r--r--classes/Profile.php1
-rw-r--r--classes/Profile_role.php2
-rw-r--r--classes/Queue_item.php11
-rw-r--r--classes/Status_network.php48
-rw-r--r--classes/Subscription.php2
-rw-r--r--classes/User.php141
-rw-r--r--classes/User_location_prefs.php53
-rw-r--r--classes/User_username.php61
-rw-r--r--classes/statusnet.ini21
23 files changed, 652 insertions, 316 deletions
diff --git a/classes/Avatar.php b/classes/Avatar.php
index 8d6424e8b..91bde0f04 100644
--- a/classes/Avatar.php
+++ b/classes/Avatar.php
@@ -37,7 +37,7 @@ class Avatar extends Memcached_DataObject
}
}
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Avatar', $kv);
}
diff --git a/classes/Config.php b/classes/Config.php
index 390d75381..43b99587f 100644
--- a/classes/Config.php
+++ b/classes/Config.php
@@ -59,7 +59,7 @@ class Config extends Memcached_DataObject
if (!empty($c)) {
$settings = $c->get(common_cache_key(self::settingsKey));
- if (!empty($settings)) {
+ if ($settings !== false) {
return $settings;
}
}
@@ -120,7 +120,7 @@ class Config extends Memcached_DataObject
return $result;
}
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Config', $kv);
}
diff --git a/classes/Fave.php b/classes/Fave.php
index 11e876ff1..8113c8e16 100644
--- a/classes/Fave.php
+++ b/classes/Fave.php
@@ -32,7 +32,7 @@ class Fave extends Memcached_DataObject
return $fave;
}
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Fave', $kv);
}
diff --git a/classes/File.php b/classes/File.php
index 03d9ca6f0..c527c4ffe 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -189,25 +189,32 @@ class File extends Memcached_DataObject
static function url($filename)
{
- $path = common_config('attachments', 'path');
+ if(common_config('site','private')) {
- if ($path[strlen($path)-1] != '/') {
- $path .= '/';
- }
+ return common_local_url('getfile',
+ array('filename' => $filename));
- if ($path[0] != '/') {
- $path = '/'.$path;
- }
+ } else {
+ $path = common_config('attachments', 'path');
- $server = common_config('attachments', 'server');
+ if ($path[strlen($path)-1] != '/') {
+ $path .= '/';
+ }
- if (empty($server)) {
- $server = common_config('site', 'server');
- }
+ if ($path[0] != '/') {
+ $path = '/'.$path;
+ }
+
+ $server = common_config('attachments', 'server');
- // XXX: protocol
+ if (empty($server)) {
+ $server = common_config('site', 'server');
+ }
- return 'http://'.$server.$path.$filename;
+ // XXX: protocol
+
+ return 'http://'.$server.$path.$filename;
+ }
}
function getEnclosure(){
diff --git a/classes/File_to_post.php b/classes/File_to_post.php
index e3db91b20..72a42b088 100644
--- a/classes/File_to_post.php
+++ b/classes/File_to_post.php
@@ -62,7 +62,7 @@ class File_to_post extends Memcached_DataObject
}
}
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('File_to_post', $kv);
}
diff --git a/classes/Group_block.php b/classes/Group_block.php
index de2cf5f6e..9f4d59295 100644
--- a/classes/Group_block.php
+++ b/classes/Group_block.php
@@ -40,7 +40,7 @@ class Group_block extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Group_block', $kv);
}
diff --git a/classes/Group_inbox.php b/classes/Group_inbox.php
index 1af7439f7..2a0787e38 100644
--- a/classes/Group_inbox.php
+++ b/classes/Group_inbox.php
@@ -20,7 +20,7 @@ class Group_inbox extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Group_inbox', $kv);
}
diff --git a/classes/Group_member.php b/classes/Group_member.php
index 3c23a991f..7b1760f76 100644
--- a/classes/Group_member.php
+++ b/classes/Group_member.php
@@ -21,8 +21,45 @@ class Group_member extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Group_member', $kv);
}
+
+ static function join($group_id, $profile_id)
+ {
+ $member = new Group_member();
+
+ $member->group_id = $group_id;
+ $member->profile_id = $profile_id;
+ $member->created = common_sql_now();
+
+ $result = $member->insert();
+
+ if (!$result) {
+ common_log_db_error($member, 'INSERT', __FILE__);
+ throw new Exception(_("Group join failed."));
+ }
+
+ return true;
+ }
+
+ static function leave($group_id, $profile_id)
+ {
+ $member = Group_member::pkeyGet(array('group_id' => $group_id,
+ 'profile_id' => $profile_id));
+
+ if (empty($member)) {
+ throw new Exception(_("Not part of group."));
+ }
+
+ $result = $member->delete();
+
+ if (!$result) {
+ common_log_db_error($member, 'INSERT', __FILE__);
+ throw new Exception(_("Group leave failed."));
+ }
+
+ return true;
+ }
}
diff --git a/classes/Inbox.php b/classes/Inbox.php
new file mode 100644
index 000000000..83cfe8ef8
--- /dev/null
+++ b/classes/Inbox.php
@@ -0,0 +1,163 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Data class for user location preferences
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Data
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @copyright 2009 StatusNet Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
+
+class Inbox extends Memcached_DataObject
+{
+ const BOXCAR = 128;
+
+ ###START_AUTOCODE
+ /* the code below is auto generated do not remove the above tag */
+
+ public $__table = 'inbox'; // table name
+ public $user_id; // int(4) primary_key not_null
+ public $notice_ids; // blob
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Inbox',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+ function sequenceKey()
+ {
+ return array(false, false, false);
+ }
+
+ /**
+ * Create a new inbox from existing Notice_inbox stuff
+ */
+
+ static function initialize($user_id)
+ {
+ $inbox = Inbox::fromNoticeInbox($user_id);
+
+ unset($inbox->fake);
+
+ $result = $inbox->insert();
+
+ if (!$result) {
+ common_log_db_error($inbox, 'INSERT', __FILE__);
+ return null;
+ }
+
+ return $inbox;
+ }
+
+ static function fromNoticeInbox($user_id)
+ {
+ $ids = array();
+
+ $ni = new Notice_inbox();
+
+ $ni->user_id = $user_id;
+ $ni->selectAdd();
+ $ni->selectAdd('notice_id');
+ $ni->orderBy('notice_id DESC');
+ $ni->limit(0, 1024);
+
+ if ($ni->find()) {
+ while($ni->fetch()) {
+ $ids[] = $ni->notice_id;
+ }
+ }
+
+ $ni->free();
+ unset($ni);
+
+ $inbox = new Inbox();
+
+ $inbox->user_id = $user_id;
+ $inbox->notice_ids = call_user_func_array('pack', array_merge(array('N*'), $ids));
+ $inbox->fake = true;
+
+ return $inbox;
+ }
+
+ static function insertNotice($user_id, $notice_id)
+ {
+ $inbox = Inbox::staticGet('user_id', $user_id);
+
+ if (empty($inbox) || $inbox->fake) {
+ $inbox = Inbox::initialize($user_id);
+ }
+
+ if (empty($inbox)) {
+ return false;
+ }
+
+ $result = $inbox->query(sprintf('UPDATE inbox '.
+ 'set notice_ids = concat(cast(0x%08x as binary(4)), '.
+ 'substr(notice_ids, 1, 4092)) '.
+ 'WHERE user_id = %d',
+ $notice_id, $user_id));
+
+ if ($result) {
+ $c = self::memcache();
+
+ if (!empty($c)) {
+ $c->delete(self::cacheKey('inbox', 'user_id', $user_id));
+ }
+ }
+
+ return $result;
+ }
+
+ static function bulkInsert($notice_id, $user_ids)
+ {
+ foreach ($user_ids as $user_id)
+ {
+ Inbox::insertNotice($user_id, $notice_id);
+ }
+ }
+
+ function stream($user_id, $offset, $limit, $since_id, $max_id, $since, $own=false)
+ {
+ $inbox = Inbox::staticGet('user_id', $user_id);
+
+ if (empty($inbox)) {
+ $inbox = Inbox::fromNoticeInbox($user_id);
+ if (empty($inbox)) {
+ return array();
+ } else {
+ $inbox->encache();
+ }
+ }
+
+ $ids = unpack('N*', $inbox->notice_ids);
+
+ // XXX: handle since_id
+ // XXX: handle max_id
+
+ $ids = array_slice($ids, $offset, $limit);
+
+ return $ids;
+ }
+}
diff --git a/classes/Login_token.php b/classes/Login_token.php
index 746cd7f22..51dc61262 100644
--- a/classes/Login_token.php
+++ b/classes/Login_token.php
@@ -40,6 +40,8 @@ class Login_token extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ const TIMEOUT = 120; // seconds after which to timeout the token
+
/*
DB_DataObject calculates the sequence key(s) by taking the first key returned by the keys() function.
In this case, the keys() function returns user_id as the first key. user_id is not a sequence, but
@@ -52,4 +54,29 @@ class Login_token extends Memcached_DataObject
{
return array(false,false);
}
+
+ function makeNew($user)
+ {
+ $login_token = Login_token::staticGet('user_id', $user->id);
+
+ if (!empty($login_token)) {
+ $login_token->delete();
+ }
+
+ $login_token = new Login_token();
+
+ $login_token->user_id = $user->id;
+ $login_token->token = common_good_rand(16);
+ $login_token->created = common_sql_now();
+
+ $result = $login_token->insert();
+
+ if (!$result) {
+ common_log_db_error($login_token, 'INSERT', __FILE__);
+ throw new Exception(sprintf(_('Could not create login token for %s'),
+ $user->nickname));
+ }
+
+ return $login_token;
+ }
}
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 21f6781c2..4ecab9db6 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -98,14 +98,16 @@ class Memcached_DataObject extends DB_DataObject
} else {
$i = DB_DataObject::factory($cls);
if (empty($i)) {
- return false;
+ $i = false;
+ return $i;
}
$result = $i->get($k, $v);
if ($result) {
$i->encache();
return $i;
} else {
- return false;
+ $i = false;
+ return $i;
}
}
}
@@ -174,7 +176,7 @@ class Memcached_DataObject extends DB_DataObject
$obj = $c->get(Memcached_DataObject::cacheKey($cls, $k, $v));
if (0 == strcasecmp($cls, 'User')) {
// Special case for User
- if (is_object($obj->id)) {
+ if (is_object($obj) && is_object($obj->id)) {
common_log(LOG_ERR, "User " . $obj->nickname . " was cached with User as ID; deleting");
$c->delete(Memcached_DataObject::cacheKey($cls, $k, $v));
return false;
@@ -329,6 +331,29 @@ class Memcached_DataObject extends DB_DataObject
$exists = false;
}
+ // @fixme horrible evil hack!
+ //
+ // In multisite configuration we don't want to keep around a separate
+ // connection for every database; we could end up with thousands of
+ // connections open per thread. In an ideal world we might keep
+ // a connection per server and select different databases, but that'd
+ // be reliant on having the same db username/pass as well.
+ //
+ // MySQL connections are cheap enough we're going to try just
+ // closing out the old connection and reopening when we encounter
+ // a new DSN.
+ //
+ // WARNING WARNING if we end up actually using multiple DBs at a time
+ // we'll need some fancier logic here.
+ if (!$exists && !empty($_DB_DATAOBJECT['CONNECTIONS'])) {
+ foreach ($_DB_DATAOBJECT['CONNECTIONS'] as $index => $conn) {
+ if (!empty($conn)) {
+ $conn->disconnect();
+ }
+ unset($_DB_DATAOBJECT['CONNECTIONS'][$index]);
+ }
+ }
+
$result = parent::_connect();
if ($result && !$exists) {
diff --git a/classes/Notice.php b/classes/Notice.php
index c2ff7fd09..a43ce867b 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -63,7 +63,7 @@ class Notice extends Memcached_DataObject
public $created; // datetime multiple_key not_null default_0000-00-00%2000%3A00%3A00
public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
public $reply_to; // int(4)
- public $is_local; // tinyint(1)
+ public $is_local; // int(4)
public $source; // varchar(32)
public $conversation; // int(4)
public $lat; // decimal(10,7)
@@ -125,8 +125,7 @@ class Notice extends Memcached_DataObject
'Fave',
'Notice_tag',
'Group_inbox',
- 'Queue_item',
- 'Notice_inbox');
+ 'Queue_item');
foreach ($related as $cls) {
$inst = new $cls();
@@ -276,7 +275,6 @@ class Notice extends Memcached_DataObject
if (isset($repeat_of)) {
$notice->repeat_of = $repeat_of;
- $notice->reply_to = $repeat_of;
} else {
$notice->reply_to = self::getReplyTo($reply_to, $profile_id, $source, $final);
}
@@ -289,29 +287,17 @@ class Notice extends Memcached_DataObject
if (!empty($lat) && !empty($lon)) {
$notice->lat = $lat;
$notice->lon = $lon;
+ }
+
+ if (!empty($location_ns) && !empty($location_id)) {
$notice->location_id = $location_id;
$notice->location_ns = $location_ns;
- } else if (!empty($location_ns) && !empty($location_id)) {
- $location = Location::fromId($location_id, $location_ns);
- if (!empty($location)) {
- $notice->lat = $location->lat;
- $notice->lon = $location->lon;
- $notice->location_id = $location_id;
- $notice->location_ns = $location_ns;
- }
- } else {
- $notice->lat = $profile->lat;
- $notice->lon = $profile->lon;
- $notice->location_id = $profile->location_id;
- $notice->location_ns = $profile->location_ns;
}
if (Event::handle('StartNoticeSave', array(&$notice))) {
// XXX: some of these functions write to the DB
- $notice->query('BEGIN');
-
$id = $notice->insert();
if (!$id) {
@@ -349,11 +335,13 @@ class Notice extends Memcached_DataObject
$notice->saveTags();
- $notice->addToInboxes();
+ $groups = $notice->saveGroups();
- $notice->saveUrls();
+ $recipients = $notice->saveReplies();
- $notice->query('COMMIT');
+ $notice->addToInboxes($groups, $recipients);
+
+ $notice->saveUrls();
Event::handle('EndNoticeSave', array($notice));
}
@@ -513,20 +501,6 @@ class Notice extends Memcached_DataObject
$original->free();
unset($original);
}
-
- $ni = new Notice_inbox();
-
- $ni->notice_id = $this->id;
-
- if ($ni->find()) {
- while ($ni->fetch()) {
- $tmk = common_cache_key('user:repeated_to_me:'.$ni->user_id);
- $cache->delete($tmk);
- }
- }
-
- $ni->free();
- unset($ni);
}
}
}
@@ -852,11 +826,24 @@ class Notice extends Memcached_DataObject
return $ids;
}
- function addToInboxes()
+ function whoGets($groups=null, $recipients=null)
{
- // XXX: loads constants
+ $c = self::memcache();
- $inbox = new Notice_inbox();
+ if (!empty($c)) {
+ $ni = $c->get(common_cache_key('notice:who_gets:'.$this->id));
+ if ($ni !== false) {
+ return $ni;
+ }
+ }
+
+ if (is_null($groups)) {
+ $groups = $this->getGroups();
+ }
+
+ if (is_null($recipients)) {
+ $recipients = $this->getReplies();
+ }
$users = $this->getSubscribedUsers();
@@ -870,7 +857,6 @@ class Notice extends Memcached_DataObject
$ni[$id] = NOTICE_INBOX_SOURCE_SUB;
}
- $groups = $this->saveGroups();
$profile = $this->getProfile();
foreach ($groups as $group) {
@@ -885,8 +871,6 @@ class Notice extends Memcached_DataObject
}
}
- $recipients = $this->saveReplies();
-
foreach ($recipients as $recipient) {
if (!array_key_exists($recipient, $ni)) {
@@ -897,7 +881,19 @@ class Notice extends Memcached_DataObject
}
}
- Notice_inbox::bulkInsert($this->id, $this->created, $ni);
+ if (!empty($c)) {
+ // XXX: pack this data better
+ $c->set(common_cache_key('notice:who_gets:'.$this->id), $ni);
+ }
+
+ return $ni;
+ }
+
+ function addToInboxes($groups, $recipients)
+ {
+ $ni = $this->whoGets($groups, $recipients);
+
+ Inbox::bulkInsert($this->id, array_keys($ni));
return;
}
@@ -931,6 +927,12 @@ class Notice extends Memcached_DataObject
function saveGroups()
{
+ // Don't save groups for repeats
+
+ if (!empty($this->repeat_of)) {
+ return array();
+ }
+
$groups = array();
/* extract all !group */
@@ -1001,6 +1003,12 @@ class Notice extends Memcached_DataObject
*/
function saveReplies()
{
+ // Don't save reply data for repeats
+
+ if (!empty($this->repeat_of)) {
+ return array();
+ }
+
// Alternative reply format
$tname = false;
if (preg_match('/^T ([A-Z0-9]{1,64}) /', $this->content, $match)) {
@@ -1087,6 +1095,52 @@ class Notice extends Memcached_DataObject
return $recipientIds;
}
+ function getReplies()
+ {
+ // XXX: cache me
+
+ $ids = array();
+
+ $reply = new Reply();
+ $reply->selectAdd();
+ $reply->selectAdd('profile_id');
+ $reply->notice_id = $this->id;
+
+ if ($reply->find()) {
+ while($reply->fetch()) {
+ $ids[] = $reply->profile_id;
+ }
+ }
+
+ $reply->free();
+
+ return $ids;
+ }
+
+ function getGroups()
+ {
+ // XXX: cache me
+
+ $ids = array();
+
+ $gi = new Group_inbox();
+
+ $gi->selectAdd();
+ $gi->selectAdd('group_id');
+
+ $gi->notice_id = $this->id;
+
+ if ($gi->find()) {
+ while ($gi->fetch()) {
+ $ids[] = $gi->group_id;
+ }
+ }
+
+ $gi->free();
+
+ return $ids;
+ }
+
function asAtomEntry($namespace=false, $source=false)
{
$profile = $this->getProfile();
@@ -1217,7 +1271,7 @@ class Notice extends Memcached_DataObject
$idstr = $cache->get($idkey);
- if (!empty($idstr)) {
+ if ($idstr !== false) {
// Cache hit! Woohoo!
$window = explode(',', $idstr);
$ids = array_slice($window, $offset, $limit);
@@ -1226,7 +1280,7 @@ class Notice extends Memcached_DataObject
$laststr = $cache->get($idkey.';last');
- if (!empty($laststr)) {
+ if ($laststr !== false) {
$window = explode(',', $laststr);
$last_id = $window[0];
$new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
@@ -1395,7 +1449,7 @@ class Notice extends Memcached_DataObject
$ids = $this->_repeatStreamDirect($limit);
} else {
$idstr = $cache->get(common_cache_key('notice:repeats:'.$this->id));
- if (!empty($idstr)) {
+ if ($idstr !== false) {
$ids = explode(',', $idstr);
} else {
$ids = $this->_repeatStreamDirect(100);
@@ -1438,4 +1492,47 @@ class Notice extends Memcached_DataObject
return $ids;
}
+
+ function locationOptions($lat, $lon, $location_id, $location_ns, $profile = null)
+ {
+ $options = array();
+
+ if (!empty($location_id) && !empty($location_ns)) {
+
+ $options['location_id'] = $location_id;
+ $options['location_ns'] = $location_ns;
+
+ $location = Location::fromId($location_id, $location_ns);
+
+ if (!empty($location)) {
+ $options['lat'] = $location->lat;
+ $options['lon'] = $location->lon;
+ }
+
+ } else if (!empty($lat) && !empty($lon)) {
+
+ $options['lat'] = $lat;
+ $options['lon'] = $lon;
+
+ $location = Location::fromLatLon($lat, $lon);
+
+ if (!empty($location)) {
+ $options['location_id'] = $location->location_id;
+ $options['location_ns'] = $location->location_ns;
+ }
+ } else if (!empty($profile)) {
+
+ if (isset($profile->lat) && isset($profile->lon)) {
+ $options['lat'] = $profile->lat;
+ $options['lon'] = $profile->lon;
+ }
+
+ if (isset($profile->location_id) && isset($profile->location_ns)) {
+ $options['location_id'] = $profile->location_id;
+ $options['location_ns'] = $profile->location_ns;
+ }
+ }
+
+ return $options;
+ }
}
diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php
index d3ddad656..c27dcdfd6 100644
--- a/classes/Notice_inbox.php
+++ b/classes/Notice_inbox.php
@@ -1,7 +1,7 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
+ * Copyright (C) 2008-2010, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -17,7 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET')) {
+ exit(1);
+}
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
@@ -29,12 +31,6 @@ define('NOTICE_INBOX_GC_MAX', 12800);
define('NOTICE_INBOX_LIMIT', 1000);
define('NOTICE_INBOX_SOFT_LIMIT', 1000);
-define('NOTICE_INBOX_SOURCE_SUB', 1);
-define('NOTICE_INBOX_SOURCE_GROUP', 2);
-define('NOTICE_INBOX_SOURCE_REPLY', 3);
-define('NOTICE_INBOX_SOURCE_FORWARD', 4);
-define('NOTICE_INBOX_SOURCE_GATEWAY', -1);
-
class Notice_inbox extends Memcached_DataObject
{
###START_AUTOCODE
@@ -55,50 +51,12 @@ class Notice_inbox extends Memcached_DataObject
function stream($user_id, $offset, $limit, $since_id, $max_id, $since, $own=false)
{
- return Notice::stream(array('Notice_inbox', '_streamDirect'),
- array($user_id, $own),
- ($own) ? 'notice_inbox:by_user:'.$user_id :
- 'notice_inbox:by_user_own:'.$user_id,
- $offset, $limit, $since_id, $max_id, $since);
+ throw new Exception('Notice_inbox no longer used; use Inbox');
}
function _streamDirect($user_id, $own, $offset, $limit, $since_id, $max_id, $since)
{
- $inbox = new Notice_inbox();
-
- $inbox->user_id = $user_id;
-
- if (!$own) {
- $inbox->whereAdd('source != ' . NOTICE_INBOX_SOURCE_GATEWAY);
- }
-
- if ($since_id != 0) {
- $inbox->whereAdd('notice_id > ' . $since_id);
- }
-
- if ($max_id != 0) {
- $inbox->whereAdd('notice_id <= ' . $max_id);
- }
-
- if (!is_null($since)) {
- $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
- }
-
- $inbox->orderBy('created DESC');
-
- if (!is_null($offset)) {
- $inbox->limit($offset, $limit);
- }
-
- $ids = array();
-
- if ($inbox->find()) {
- while ($inbox->fetch()) {
- $ids[] = $inbox->notice_id;
- }
- }
-
- return $ids;
+ throw new Exception('Notice_inbox no longer used; use Inbox');
}
function &pkeyGet($kv)
@@ -106,88 +64,18 @@ class Notice_inbox extends Memcached_DataObject
return Memcached_DataObject::pkeyGet('Notice_inbox', $kv);
}
- /**
- * Trim inbox for a given user to latest NOTICE_INBOX_LIMIT items
- * (up to NOTICE_INBOX_GC_MAX will be deleted).
- *
- * @param int $user_id
- * @return int count of notices dropped from the inbox, if any
- */
static function gc($user_id)
{
- $entry = new Notice_inbox();
- $entry->user_id = $user_id;
- $entry->orderBy('created DESC');
- $entry->limit(NOTICE_INBOX_LIMIT - 1, NOTICE_INBOX_GC_MAX);
-
- $total = $entry->find();
-
- if ($total > 0) {
- $notices = array();
- $cnt = 0;
- while ($entry->fetch()) {
- $notices[] = $entry->notice_id;
- $cnt++;
- if ($cnt >= NOTICE_INBOX_GC_BOXCAR) {
- self::deleteMatching($user_id, $notices);
- $notices = array();
- $cnt = 0;
- }
- }
-
- if ($cnt > 0) {
- self::deleteMatching($user_id, $notices);
- $notices = array();
- }
- }
-
- return $total;
+ throw new Exception('Notice_inbox no longer used; use Inbox');
}
static function deleteMatching($user_id, $notices)
{
- $entry = new Notice_inbox();
- return $entry->query('DELETE FROM notice_inbox '.
- 'WHERE user_id = ' . $user_id . ' ' .
- 'AND notice_id in ('.implode(',', $notices).')');
+ throw new Exception('Notice_inbox no longer used; use Inbox');
}
static function bulkInsert($notice_id, $created, $ni)
{
- $cnt = 0;
-
- $qryhdr = 'INSERT INTO notice_inbox (user_id, notice_id, source, created) VALUES ';
- $qry = $qryhdr;
-
- foreach ($ni as $id => $source) {
- if ($cnt > 0) {
- $qry .= ', ';
- }
- $qry .= '('.$id.', '.$notice_id.', '.$source.", '".$created. "') ";
- $cnt++;
- if (rand() % NOTICE_INBOX_SOFT_LIMIT == 0) {
- // FIXME: Causes lag in replicated servers
- // Notice_inbox::gc($id);
- }
- if ($cnt >= MAX_BOXCARS) {
- $inbox = new Notice_inbox();
- $result = $inbox->query($qry);
- if (PEAR::isError($result)) {
- common_log_db_error($inbox, $qry);
- }
- $qry = $qryhdr;
- $cnt = 0;
- }
- }
-
- if ($cnt > 0) {
- $inbox = new Notice_inbox();
- $result = $inbox->query($qry);
- if (PEAR::isError($result)) {
- common_log_db_error($inbox, $qry);
- }
- }
-
- return;
+ throw new Exception('Notice_inbox no longer used; use Inbox');
}
}
diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php
index 02740280f..79231f0b0 100644
--- a/classes/Notice_tag.php
+++ b/classes/Notice_tag.php
@@ -96,7 +96,7 @@ class Notice_tag extends Memcached_DataObject
}
}
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Notice_tag', $kv);
}
diff --git a/classes/Profile.php b/classes/Profile.php
index 03196447b..25d908dbf 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -504,6 +504,7 @@ class Profile extends Memcached_DataObject
'Reply',
'Group_member',
);
+ Event::handle('ProfileDeleteRelated', array($this, &$related));
foreach ($related as $cls) {
$inst = new $cls();
diff --git a/classes/Profile_role.php b/classes/Profile_role.php
index afa7fb74e..74aca3730 100644
--- a/classes/Profile_role.php
+++ b/classes/Profile_role.php
@@ -43,7 +43,7 @@ class Profile_role extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Profile_role', $kv);
}
diff --git a/classes/Queue_item.php b/classes/Queue_item.php
index 295c321b5..cf805a606 100644
--- a/classes/Queue_item.php
+++ b/classes/Queue_item.php
@@ -25,10 +25,12 @@ class Queue_item extends Memcached_DataObject
function sequenceKey()
{ return array(false, false); }
- static function top($transport) {
+ static function top($transport=null) {
$qi = new Queue_item();
- $qi->transport = $transport;
+ if ($transport) {
+ $qi->transport = $transport;
+ }
$qi->orderBy('created');
$qi->whereAdd('claimed is null');
@@ -40,7 +42,8 @@ class Queue_item extends Memcached_DataObject
# XXX: potential race condition
# can we force it to only update if claimed is still null
# (or old)?
- common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id . ' for transport ' . $transport);
+ common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id .
+ ' for transport ' . $qi->transport);
$orig = clone($qi);
$qi->claimed = common_sql_now();
$result = $qi->update($orig);
@@ -55,7 +58,7 @@ class Queue_item extends Memcached_DataObject
return null;
}
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Queue_item', $kv);
}
diff --git a/classes/Status_network.php b/classes/Status_network.php
index b3117640d..ef8e1ed43 100644
--- a/classes/Status_network.php
+++ b/classes/Status_network.php
@@ -49,6 +49,13 @@ class Status_network extends DB_DataObject
static $cache = null;
static $base = null;
+ /**
+ * @param string $dbhost
+ * @param string $dbuser
+ * @param string $dbpass
+ * @param string $dbname
+ * @param array $servers memcached servers to use for caching config info
+ */
static function setupDB($dbhost, $dbuser, $dbpass, $dbname, $servers)
{
global $config;
@@ -60,12 +67,17 @@ class Status_network extends DB_DataObject
if (class_exists('Memcache')) {
self::$cache = new Memcache();
+ // Can't close persistent connections, making forking painful.
+ //
+ // @fixme only do this in *parent* CLI processes.
+ // single-process and child-processes *should* use persistent.
+ $persist = php_sapi_name() != 'cli';
if (is_array($servers)) {
foreach($servers as $server) {
- self::$cache->addServer($server);
+ self::$cache->addServer($server, 11211, $persist);
}
} else {
- self::$cache->addServer($servers);
+ self::$cache->addServer($servers, 11211, $persist);
}
}
@@ -89,7 +101,7 @@ class Status_network extends DB_DataObject
if (empty($sn)) {
$sn = self::staticGet($k, $v);
if (!empty($sn)) {
- self::$cache->set($ck, $sn);
+ self::$cache->set($ck, clone($sn));
}
}
@@ -121,6 +133,11 @@ class Status_network extends DB_DataObject
return parent::delete();
}
+ /**
+ * @param string $servername hostname
+ * @param string $pathname URL base path
+ * @param string $wildcard hostname suffix to match wildcard config
+ */
static function setupSite($servername, $pathname, $wildcard)
{
global $config;
@@ -150,9 +167,19 @@ class Status_network extends DB_DataObject
}
if (!empty($sn)) {
- if (!empty($sn->hostname) && 0 != strcasecmp($sn->hostname, $servername)) {
- $sn->redirectToHostname();
+
+ // Redirect to the right URL
+
+ if (!empty($sn->hostname) &&
+ empty($_SERVER['HTTPS']) &&
+ 0 != strcasecmp($sn->hostname, $servername)) {
+ $sn->redirectTo('http://'.$sn->hostname.$_SERVER['REQUEST_URI']);
+ } else if (!empty($_SERVER['HTTPS']) &&
+ 0 != strcasecmp($sn->hostname, $servername) &&
+ 0 != strcasecmp($sn->nickname.'.'.$wildcard, $servername)) {
+ $sn->redirectTo('https://'.$sn->nickname.'.'.$wildcard.$_SERVER['REQUEST_URI']);
}
+
$dbhost = (empty($sn->dbhost)) ? 'localhost' : $sn->dbhost;
$dbuser = (empty($sn->dbuser)) ? $sn->nickname : $sn->dbuser;
$dbpass = $sn->dbpass;
@@ -160,7 +187,11 @@ class Status_network extends DB_DataObject
$config['db']['database'] = "mysqli://$dbuser:$dbpass@$dbhost/$dbname";
- $config['site']['name'] = $sn->sitename;
+ $config['site']['name'] = $sn->sitename;
+
+ if (!empty($sn->hostname)) {
+ $config['site']['server'] = $sn->hostname;
+ }
if (!empty($sn->theme)) {
$config['site']['theme'] = $sn->theme;
@@ -179,11 +210,8 @@ class Status_network extends DB_DataObject
// (C) 2006 by Heiko Richler http://www.richler.de/
// LGPL
- function redirectToHostname()
+ function redirectTo($destination)
{
- $destination = 'http://'.$this->hostname;
- $destination .= $_SERVER['REQUEST_URI'];
-
$old = 'http'.
(($_SERVER['HTTPS'] == 'on') ? 'S' : '').
'://'.
diff --git a/classes/Subscription.php b/classes/Subscription.php
index fedfd5f19..faf1331cd 100644
--- a/classes/Subscription.php
+++ b/classes/Subscription.php
@@ -46,7 +46,7 @@ class Subscription extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Subscription', $kv);
}
diff --git a/classes/User.php b/classes/User.php
index 6708d95b6..d6b52be01 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -291,6 +291,20 @@ class User extends Memcached_DataObject
return false;
}
+ // Everyone gets an inbox
+
+ $inbox = new Inbox();
+
+ $inbox->user_id = $user->id;
+ $inbox->notice_ids = '';
+
+ $result = $inbox->insert();
+
+ if (!$result) {
+ common_log_db_error($inbox, 'INSERT', __FILE__);
+ return false;
+ }
+
// Everyone is subscribed to themself
$subscription = new Subscription();
@@ -482,89 +496,30 @@ class User extends Memcached_DataObject
function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
-
+ $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
return Notice::getStreamByIds($ids);
}
function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
-
+ $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
return Notice::getStreamByIds($ids);
}
function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Notice::stream(array($this, '_friendsTimelineDirect'),
- array(false),
- 'user:friends_timeline:'.$this->id,
- $offset, $limit, $since_id, $before_id, $since);
+ $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
return Notice::getStreamByIds($ids);
}
function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Notice::stream(array($this, '_friendsTimelineDirect'),
- array(true),
- 'user:friends_timeline_own:'.$this->id,
- $offset, $limit, $since_id, $before_id, $since);
+ $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
return Notice::getStreamByIds($ids);
}
- function _friendsTimelineDirect($own, $offset, $limit, $since_id, $max_id, $since)
- {
- $qry =
- 'SELECT notice.id AS id ' .
- 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' .
- 'WHERE notice_inbox.user_id = ' . $this->id . ' ' .
- 'AND notice.repeat_of IS NULL ';
-
- if (!$own) {
- // XXX: autoload notice inbox for constant
- $inbox = new Notice_inbox();
-
- $qry .= 'AND notice_inbox.source != ' . NOTICE_INBOX_SOURCE_GATEWAY . ' ';
- }
-
- if ($since_id != 0) {
- $qry .= 'AND notice.id > ' . $since_id . ' ';
- }
-
- if ($max_id != 0) {
- $qry .= 'AND notice.id <= ' . $max_id . ' ';
- }
-
- if (!is_null($since)) {
- $qry .= 'AND notice.modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
- }
-
- // NOTE: we sort by fave time, not by notice time!
-
- $qry .= 'ORDER BY notice_id DESC ';
-
- if (!is_null($offset)) {
- $qry .= "LIMIT $limit OFFSET $offset";
- }
-
- $ids = array();
-
- $notice = new Notice();
-
- $notice->query($qry);
-
- while ($notice->fetch()) {
- $ids[] = $notice->id;
- }
-
- $notice->free();
- $notice = NULL;
-
- return $ids;
- }
-
function blowFavesCache()
{
$cache = common_memcache();
@@ -777,7 +732,6 @@ class User extends Memcached_DataObject
'Remember_me',
'Foreign_link',
'Invitation',
- 'Notice_inbox',
);
Event::handle('UserDeleteRelated', array($this, &$related));
@@ -945,55 +899,30 @@ class User extends Memcached_DataObject
function repeatedToMe($offset=0, $limit=20, $since_id=null, $max_id=null)
{
- $ids = Notice::stream(array($this, '_repeatedToMeDirect'),
- array(),
- 'user:repeated_to_me:'.$this->id,
- $offset, $limit, $since_id, $max_id, null);
-
- return Notice::getStreamByIds($ids);
+ throw new Exception("Not implemented since inbox change.");
}
- function _repeatedToMeDirect($offset, $limit, $since_id, $max_id, $since)
+ function shareLocation()
{
- $qry =
- 'SELECT notice.id AS id ' .
- 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' .
- 'WHERE notice_inbox.user_id = ' . $this->id . ' ' .
- 'AND notice.repeat_of IS NOT NULL ';
+ $cfg = common_config('location', 'share');
- if ($since_id != 0) {
- $qry .= 'AND notice.id > ' . $since_id . ' ';
- }
-
- if ($max_id != 0) {
- $qry .= 'AND notice.id <= ' . $max_id . ' ';
- }
-
- if (!is_null($since)) {
- $qry .= 'AND notice.modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
- }
-
- // NOTE: we sort by fave time, not by notice time!
-
- $qry .= 'ORDER BY notice.id DESC ';
-
- if (!is_null($offset)) {
- $qry .= "LIMIT $limit OFFSET $offset";
- }
-
- $ids = array();
+ if ($cfg == 'always') {
+ return true;
+ } else if ($cfg == 'never') {
+ return false;
+ } else { // user
+ $share = true;
- $notice = new Notice();
+ $prefs = User_location_prefs::staticGet('user_id', $this->id);
- $notice->query($qry);
+ if (empty($prefs)) {
+ $share = common_config('location', 'sharedefault');
+ } else {
+ $share = $prefs->share_location;
+ $prefs->free();
+ }
- while ($notice->fetch()) {
- $ids[] = $notice->id;
+ return $share;
}
-
- $notice->free();
- $notice = NULL;
-
- return $ids;
}
}
diff --git a/classes/User_location_prefs.php b/classes/User_location_prefs.php
new file mode 100644
index 000000000..bd6029f97
--- /dev/null
+++ b/classes/User_location_prefs.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Data class for user location preferences
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Data
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @copyright 2009 StatusNet Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
+
+class User_location_prefs extends Memcached_DataObject
+{
+ ###START_AUTOCODE
+ /* the code below is auto generated do not remove the above tag */
+
+ public $__table = 'user_location_prefs'; // table name
+ public $user_id; // int(4) primary_key not_null
+ public $share_location; // tinyint(1) default_1
+ public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00
+ public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_location_prefs',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+ function sequenceKey()
+ {
+ return array(false, false, false);
+ }
+}
diff --git a/classes/User_username.php b/classes/User_username.php
new file mode 100644
index 000000000..853fd5cb8
--- /dev/null
+++ b/classes/User_username.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Table Definition for user_username
+ */
+require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
+
+class User_username extends Memcached_DataObject
+{
+ ###START_AUTOCODE
+ /* the code below is auto generated do not remove the above tag */
+
+ public $__table = 'user_username'; // table name
+ public $user_id; // int(4) not_null
+ public $provider_name; // varchar(255) primary_key not_null
+ public $username; // varchar(255) primary_key not_null
+ public $created; // datetime() not_null
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
+
+ /* Static get */
+ function staticGet($k,$v=null)
+ { return Memcached_DataObject::staticGet('User_username',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+ /**
+ * Register a user with a username on a given provider
+ * @param User User object
+ * @param string username on the given provider
+ * @param provider_name string name of the provider
+ * @return mixed User_username instance if the registration succeeded, false if it did not
+ */
+ static function register($user, $username, $provider_name)
+ {
+ $user_username = new User_username();
+ $user_username->user_id = $user->id;
+ $user_username->provider_name = $provider_name;
+ $user_username->username = $username;
+ $user_username->created = DB_DataObject_Cast::dateTime();
+ if($user_username->insert()){
+ return $user_username;
+ }else{
+ return false;
+ }
+ }
+
+ function table() {
+ return array(
+ 'user_id' => DB_DATAOBJECT_INT,
+ 'username' => DB_DATAOBJECT_STR,
+ 'provider_name' => DB_DATAOBJECT_STR ,
+ 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
+ );
+ }
+
+ // now define the keys.
+ function keys() {
+ return array('provider_name', 'username');
+ }
+
+}
diff --git a/classes/statusnet.ini b/classes/statusnet.ini
index 2cc37dbfe..73727a6d6 100644
--- a/classes/statusnet.ini
+++ b/classes/statusnet.ini
@@ -1,4 +1,3 @@
-
[avatar]
profile_id = 129
original = 17
@@ -93,6 +92,7 @@ modified = 384
[file__keys]
id = N
+url = U
[file_oembed]
file_id = 129
@@ -241,6 +241,13 @@ address = 130
address_type = 130
created = 142
+[inbox]
+user_id = 129
+notice_ids = 66
+
+[inbox__keys]
+user_id = K
+
[invitation__keys]
code = K
@@ -564,4 +571,14 @@ modified = 384
[user_openid__keys]
trustroot = K
-user_id = K \ No newline at end of file
+user_id = K
+
+[user_location_prefs]
+user_id = 129
+share_location = 17
+created = 142
+modified = 384
+
+[user_location_prefs__keys]
+user_id = K
+