summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorBrenda Wallace <shiny@cpan.org>2010-01-09 21:43:25 +0000
committerBrenda Wallace <shiny@cpan.org>2010-01-09 21:43:25 +0000
commit4de09d6bd4eab3259d42fa846e4dd31f2516a038 (patch)
treedf650402df1abcb64e1aa9640eeeb782b3c20f03 /classes
parentf4459dfedcdea2f2a6078bedf9530deb45b6d52c (diff)
parentf396701b6466749c09ce16b1e7f2f96c10b05cdd (diff)
Merge commit 'origin/0.9.x' into 0.9.x
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.php2
-rw-r--r--classes/Memcached_DataObject.php201
-rw-r--r--classes/Notice.php84
-rw-r--r--classes/Notice_inbox.php11
-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.php2
-rw-r--r--classes/Subscription.php2
-rw-r--r--classes/User.php30
-rw-r--r--classes/User_location_prefs.php53
-rw-r--r--classes/User_username.php61
-rw-r--r--classes/statusnet.ini14
20 files changed, 405 insertions, 107 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 e04a9d525..6173f31d6 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -182,25 +182,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..069b2c7a1 100644
--- a/classes/Group_member.php
+++ b/classes/Group_member.php
@@ -21,7 +21,7 @@ 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);
}
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index be8137573..400b05f97 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -19,8 +19,6 @@
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-
class Memcached_DataObject extends DB_DataObject
{
/**
@@ -38,6 +36,41 @@ class Memcached_DataObject extends DB_DataObject
}
/**
+ * Magic function called at serialize() time.
+ *
+ * We use this to drop a couple process-specific references
+ * from DB_DataObject which can cause trouble in future
+ * processes.
+ *
+ * @return array of variable names to include in serialization.
+ */
+ function __sleep()
+ {
+ $vars = array_keys(get_object_vars($this));
+ $skip = array('_DB_resultid', '_link_loaded');
+ return array_diff($vars, $skip);
+ }
+
+ /**
+ * Magic function called at unserialize() time.
+ *
+ * Clean out some process-specific variables which might
+ * be floating around from a previous process's cached
+ * objects.
+ *
+ * Old cached objects may still have them.
+ */
+ function __wakeup()
+ {
+ // Refers to global state info from a previous process.
+ // Clear this out so we don't accidentally break global
+ // state in *this* process.
+ $this->_DB_resultid = null;
+ // We don't have any local DBO refs, so clear these out.
+ $this->_link_loaded = false;
+ }
+
+ /**
* Wrapper for DB_DataObject's static lookup using memcached
* as backing instead of an in-process cache array.
*
@@ -57,31 +90,42 @@ class Memcached_DataObject extends DB_DataObject
unset($i);
}
$i = Memcached_DataObject::getcached($cls, $k, $v);
- if ($i) {
- return $i;
- } else {
- $i = DB_DataObject::staticGet($cls, $k, $v);
- if ($i) {
- // DB_DataObject's in-process lookup cache interferes with GC
- // to cause massive memory leaks in long-running processes.
- if (php_sapi_name() == 'cli') {
- $i->_clear_cache();
- }
-
- // Now store it into the shared memcached, if present...
+ if ($i === false) { // false == cache miss
+ $i = DB_DataObject::factory($cls);
+ if (empty($i)) {
+ $i = false;
+ return $i;
+ }
+ $result = $i->get($k, $v);
+ if ($result) {
+ // Hit!
$i->encache();
+ } else {
+ // save the fact that no such row exists
+ $c = self::memcache();
+ if (!empty($c)) {
+ $ck = self::cachekey($cls, $k, $v);
+ $c->set($ck, null);
+ }
+ $i = false;
}
- return $i;
}
+ return $i;
}
- function &pkeyGet($cls, $kv)
+ /**
+ * @fixme Should this return false on lookup fail to match staticGet?
+ */
+ function pkeyGet($cls, $kv)
{
$i = Memcached_DataObject::multicache($cls, $kv);
- if ($i) {
+ if ($i !== false) { // false == cache miss
return $i;
} else {
- $i = new $cls();
+ $i = DB_DataObject::factory($cls);
+ if (empty($i)) {
+ return false;
+ }
foreach ($kv as $k => $v) {
$i->$k = $v;
}
@@ -89,6 +133,11 @@ class Memcached_DataObject extends DB_DataObject
$i->encache();
} else {
$i = null;
+ $c = self::memcache();
+ if (!empty($c)) {
+ $ck = self::multicacheKey($cls, $kv);
+ $c->set($ck, null);
+ }
}
return $i;
}
@@ -97,6 +146,9 @@ class Memcached_DataObject extends DB_DataObject
function insert()
{
$result = parent::insert();
+ if ($result) {
+ $this->encache(); // in case of cached negative lookups
+ }
return $result;
}
@@ -123,7 +175,7 @@ class Memcached_DataObject extends DB_DataObject
}
static function cacheKey($cls, $k, $v) {
- if (is_object($cls) || is_object($j) || is_object($v)) {
+ if (is_object($cls) || is_object($k) || is_object($v)) {
$e = new Exception();
common_log(LOG_ERR, __METHOD__ . ' object in param: ' .
str_replace("\n", " ", $e->getTraceAsString()));
@@ -142,6 +194,17 @@ class Memcached_DataObject extends DB_DataObject
function keyTypes()
{
+ // ini-based classes return number-indexed arrays. handbuilt
+ // classes return column => keytype. Make this uniform.
+
+ $keys = $this->keys();
+
+ $keyskeys = array_keys($keys);
+
+ if (is_string($keyskeys[0])) {
+ return $keys;
+ }
+
global $_DB_DATAOBJECT;
if (!isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"])) {
$this->databaseStructure();
@@ -153,67 +216,90 @@ class Memcached_DataObject extends DB_DataObject
function encache()
{
$c = $this->memcache();
+
if (!$c) {
return false;
- } else {
- $pkey = array();
- $pval = array();
- $types = $this->keyTypes();
- ksort($types);
- foreach ($types as $key => $type) {
- if ($type == 'K') {
- $pkey[] = $key;
- $pval[] = $this->$key;
- } else {
- $c->set($this->cacheKey($this->tableName(), $key, $this->$key), $this);
- }
- }
- # XXX: should work for both compound and scalar pkeys
- $pvals = implode(',', $pval);
- $pkeys = implode(',', $pkey);
- $c->set($this->cacheKey($this->tableName(), $pkeys, $pvals), $this);
+ }
+
+ $keys = $this->_allCacheKeys();
+
+ foreach ($keys as $key) {
+ $c->set($key, $this);
}
}
function decache()
{
$c = $this->memcache();
+
if (!$c) {
return false;
- } else {
- $pkey = array();
- $pval = array();
- $types = $this->keyTypes();
- ksort($types);
- foreach ($types as $key => $type) {
- if ($type == 'K') {
- $pkey[] = $key;
- $pval[] = $this->$key;
- } else {
- $c->delete($this->cacheKey($this->tableName(), $key, $this->$key));
+ }
+
+ $keys = $this->_allCacheKeys();
+
+ foreach ($keys as $key) {
+ $c->delete($key, $this);
+ }
+ }
+
+ function _allCacheKeys()
+ {
+ $ckeys = array();
+
+ $types = $this->keyTypes();
+ ksort($types);
+
+ $pkey = array();
+ $pval = array();
+
+ foreach ($types as $key => $type) {
+
+ assert(!empty($key));
+
+ if ($type == 'U') {
+ if (empty($this->$key)) {
+ continue;
}
+ $ckeys[] = $this->cacheKey($this->tableName(), $key, $this->$key);
+ } else if ($type == 'K' || $type == 'N') {
+ $pkey[] = $key;
+ $pval[] = $this->$key;
+ } else {
+ throw new Exception("Unknown key type $key => $type for " . $this->tableName());
}
- # should work for both compound and scalar pkeys
- # XXX: comma works for now but may not be safe separator for future keys
- $pvals = implode(',', $pval);
- $pkeys = implode(',', $pkey);
- $c->delete($this->cacheKey($this->tableName(), $pkeys, $pvals));
}
+
+ assert(count($pkey) > 0);
+
+ // XXX: should work for both compound and scalar pkeys
+ $pvals = implode(',', $pval);
+ $pkeys = implode(',', $pkey);
+
+ $ckeys[] = $this->cacheKey($this->tableName(), $pkeys, $pvals);
+
+ return $ckeys;
}
function multicache($cls, $kv)
{
ksort($kv);
- $c = Memcached_DataObject::memcache();
+ $c = self::memcache();
if (!$c) {
return false;
} else {
- $pkeys = implode(',', array_keys($kv));
- $pvals = implode(',', array_values($kv));
- return $c->get(Memcached_DataObject::cacheKey($cls, $pkeys, $pvals));
+ return $c->get(self::multicacheKey($cls, $kv));
}
}
+ static function multicacheKey($cls, $kv)
+ {
+ ksort($kv);
+ $pkeys = implode(',', array_keys($kv));
+ $pvals = implode(',', array_values($kv));
+ return self::cacheKey($cls, $pkeys, $pvals);
+ }
+
function getSearchEngine($table)
{
require_once INSTALLDIR.'/lib/search_engines.php';
@@ -248,7 +334,8 @@ class Memcached_DataObject extends DB_DataObject
$key_part = common_keyize($cls).':'.md5($qry);
$ckey = common_cache_key($key_part);
$stored = $c->get($ckey);
- if ($stored) {
+
+ if ($stored !== false) {
return new ArrayWrapper($stored);
}
diff --git a/classes/Notice.php b/classes/Notice.php
index 7651d8bd5..9bda47827 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)
@@ -214,7 +214,7 @@ class Notice extends Memcached_DataObject
extract($options);
}
- if (empty($is_local)) {
+ if (!isset($is_local)) {
$is_local = Notice::LOCAL_PUBLIC;
}
@@ -289,21 +289,11 @@ 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))) {
@@ -1139,7 +1129,7 @@ class Notice extends Memcached_DataObject
$xs->element('id', null, $this->uri);
$xs->element('published', null, common_date_w3dtf($this->created));
- $xs->element('updated', null, common_date_w3dtf($this->modified));
+ $xs->element('updated', null, common_date_w3dtf($this->created));
if ($this->reply_to) {
$reply_notice = Notice::staticGet('id', $this->reply_to);
@@ -1217,7 +1207,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 +1216,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,
@@ -1366,12 +1356,21 @@ class Notice extends Memcached_DataObject
{
$author = Profile::staticGet('id', $this->profile_id);
- // FIXME: truncate on long repeats...?
-
$content = sprintf(_('RT @%1$s %2$s'),
$author->nickname,
$this->content);
+ $maxlen = common_config('site', 'textlimit');
+ if ($maxlen > 0 && mb_strlen($content) > $maxlen) {
+ // Web interface and current Twitter API clients will
+ // pull the original notice's text, but some older
+ // clients and RSS/Atom feeds will see this trimmed text.
+ //
+ // Unfortunately this is likely to lose tags or URLs
+ // at the end of long notices.
+ $content = mb_substr($content, 0, $maxlen - 4) . ' ...';
+ }
+
return self::saveNew($repeater_id, $content, $source,
array('repeat_of' => $this->id));
}
@@ -1386,7 +1385,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);
@@ -1429,4 +1428,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 b39006542..e350e6e2f 100644
--- a/classes/Notice_inbox.php
+++ b/classes/Notice_inbox.php
@@ -101,11 +101,18 @@ class Notice_inbox extends Memcached_DataObject
return $ids;
}
- function &pkeyGet($kv)
+ function pkeyGet($kv)
{
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();
@@ -133,6 +140,8 @@ class Notice_inbox extends Memcached_DataObject
$notices = array();
}
}
+
+ return $total;
}
static function deleteMatching($user_id, $notices)
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..9c673540d 100644
--- a/classes/Queue_item.php
+++ b/classes/Queue_item.php
@@ -55,7 +55,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/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 484dc8c82..34151778c 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -625,7 +625,11 @@ class User extends Memcached_DataObject
// Cancel their subscription, if it exists
- subs_unsubscribe_to($other->getUser(),$this->getProfile());
+ $otherUser = User::staticGet('id', $other->id);
+
+ if (!empty($otherUser)) {
+ subs_unsubscribe_to($otherUser, $this->getProfile());
+ }
$block->query('COMMIT');
@@ -992,4 +996,28 @@ class User extends Memcached_DataObject
return $ids;
}
+
+ function shareLocation()
+ {
+ $cfg = common_config('location', 'share');
+
+ if ($cfg == 'always') {
+ return true;
+ } else if ($cfg == 'never') {
+ return false;
+ } else { // user
+ $share = true;
+
+ $prefs = User_location_prefs::staticGet('user_id', $this->id);
+
+ if (empty($prefs)) {
+ $share = common_config('location', 'sharedefault');
+ } else {
+ $share = $prefs->share_location;
+ $prefs->free();
+ }
+
+ return $share;
+ }
+ }
}
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..0db2c5d6e 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
@@ -564,4 +564,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
+