summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/Design.php2
-rw-r--r--classes/Fave.php44
-rw-r--r--classes/File.php76
-rw-r--r--classes/File_oembed.php35
-rw-r--r--classes/File_redirection.php124
-rw-r--r--classes/File_thumbnail.php17
-rw-r--r--classes/File_to_post.php28
-rw-r--r--classes/Foreign_user.php22
-rw-r--r--classes/Group_inbox.php6
-rw-r--r--classes/Memcached_DataObject.php9
-rw-r--r--classes/Notice.php226
-rw-r--r--classes/Notice_inbox.php1
-rw-r--r--classes/Profile.php48
-rw-r--r--classes/Session.php129
-rw-r--r--classes/Status_network.php7
-rw-r--r--classes/User.php52
-rw-r--r--classes/User_group.php48
-rw-r--r--[-rwxr-xr-x]classes/laconica.ini39
18 files changed, 645 insertions, 268 deletions
diff --git a/classes/Design.php b/classes/Design.php
index da4b670be..0927fcda7 100644
--- a/classes/Design.php
+++ b/classes/Design.php
@@ -85,7 +85,7 @@ class Design extends Memcached_DataObject
$css .= 'body { background-image:url(' .
Design::url($this->backgroundimage) .
- '); ' . $repeat . ' }' . "\n";
+ '); ' . $repeat . ' background-attachment:fixed; }' . "\n";
}
$out->element('style', array('type' => 'text/css'), $css);
diff --git a/classes/Fave.php b/classes/Fave.php
index 572334ce4..c3ec62dcf 100644
--- a/classes/Fave.php
+++ b/classes/Fave.php
@@ -37,52 +37,62 @@ class Fave extends Memcached_DataObject
return Memcached_DataObject::pkeyGet('Fave', $kv);
}
- function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE)
+ function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $own=false)
{
$ids = Notice::stream(array('Fave', '_streamDirect'),
- array($user_id),
+ array($user_id, $own),
+ ($own) ? 'fave:ids_by_user_own:'.$user_id :
'fave:ids_by_user:'.$user_id,
$offset, $limit);
return $ids;
}
- function _streamDirect($user_id, $offset, $limit, $since_id, $max_id, $since)
+ function _streamDirect($user_id, $own, $offset, $limit, $since_id, $max_id, $since)
{
$fav = new Fave();
-
- $fav->user_id = $user_id;
-
- $fav->selectAdd();
- $fav->selectAdd('notice_id');
+ $qry = null;
+
+ if ($own) {
+ $qry = 'SELECT fave.* FROM fave ';
+ $qry .= 'WHERE fave.user_id = ' . $user_id . ' ';
+ } else {
+ $qry = 'SELECT fave.* FROM fave ';
+ $qry .= 'INNER JOIN notice ON fave.notice_id = notice.id ';
+ $qry .= 'WHERE fave.user_id = ' . $user_id . ' ';
+ $qry .= 'AND notice.is_local != ' . NOTICE_GATEWAY . ' ';
+ }
if ($since_id != 0) {
- $fav->whereAdd('notice_id > ' . $since_id);
+ $qry .= 'AND notice_id > ' . $since_id . ' ';
}
if ($max_id != 0) {
- $fav->whereAdd('notice_id <= ' . $max_id);
+ $qry .= 'AND notice_id <= ' . $max_id . ' ';
}
if (!is_null($since)) {
- $fav->whereAdd('modified > \'' . date('Y-m-d H:i:s', $since) . '\'');
+ $qry .= 'AND modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
}
// NOTE: we sort by fave time, not by notice time!
- $fav->orderBy('modified DESC');
+ $qry .= 'ORDER BY modified DESC ';
if (!is_null($offset)) {
- $fav->limit($offset, $limit);
+ $qry .= "LIMIT $offset, $limit";
}
+ $fav->query($qry);
+
$ids = array();
- if ($fav->find()) {
- while ($fav->fetch()) {
- $ids[] = $fav->notice_id;
- }
+ while ($fav->fetch()) {
+ $ids[] = $fav->notice_id;
}
+ $fav->free();
+ unset($fav);
+
return $ids;
}
}
diff --git a/classes/File.php b/classes/File.php
index 890536035..5dd7cd865 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -30,22 +30,24 @@ require_once INSTALLDIR.'/classes/File_to_post.php';
* Table Definition for file
*/
-class File extends Memcached_DataObject
+class File extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'file'; // table name
- public $id; // int(11) not_null primary_key group_by
+ public $id; // int(4) primary_key not_null
public $url; // varchar(255) unique_key
- public $mimetype; // varchar(50)
- public $size; // int(11) group_by
- public $title; // varchar(255)
- public $date; // int(11) group_by
- public $protected; // int(1) group_by
+ public $mimetype; // varchar(50)
+ public $size; // int(4)
+ public $title; // varchar(255)
+ public $date; // int(4)
+ public $protected; // int(4)
+ public $filename; // varchar(255)
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('File',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
@@ -89,9 +91,10 @@ class File extends Memcached_DataObject
$given_url = File_redirection::_canonUrl($given_url);
if (empty($given_url)) return -1; // error, no url to process
$file = File::staticGet('url', $given_url);
- if (empty($file->id)) {
+ if (empty($file)) {
$file_redir = File_redirection::staticGet('url', $given_url);
- if (empty($file_redir->id)) {
+ if (empty($file_redir)) {
+ common_debug("processNew() '$given_url' not a known redirect.\n");
$redir_data = File_redirection::where($given_url);
$redir_url = $redir_data['url'];
if ($redir_url === $given_url) {
@@ -114,7 +117,7 @@ class File extends Memcached_DataObject
$x = File::staticGet($file_id);
if (empty($x)) die('Impossible!');
}
-
+
File_to_post::processNew($file_id, $notice_id);
return $x;
}
@@ -122,8 +125,8 @@ class File extends Memcached_DataObject
function isRespectsQuota($user) {
if ($_FILES['attach']['size'] > 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.'),
- common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
+ 'and the file you sent was %d bytes. Try to upload a smaller version.'),
+ common_config('attachments', 'file_quota'), $_FILES['attach']['size']);
}
$query = "select sum(size) as total from file join file_to_post on file_to_post.file_id = file.id join notice on file_to_post.post_id = notice.id where profile_id = {$user->id} and file.url like '%/notice/%/file'";
@@ -143,5 +146,52 @@ class File extends Memcached_DataObject
}
return true;
}
+
+ // where should the file go?
+
+ static function filename($profile, $basename, $mimetype)
+ {
+ require_once 'MIME/Type/Extension.php';
+ $mte = new MIME_Type_Extension();
+ $ext = $mte->getExtension($mimetype);
+ $nickname = $profile->nickname;
+ $datestamp = strftime('%Y%m%dT%H%M%S', time());
+ $random = strtolower(common_confirmation_code(32));
+ return "$nickname-$datestamp-$random.$ext";
+ }
+
+ static function path($filename)
+ {
+ $dir = common_config('attachments', 'dir');
+
+ if ($dir[strlen($dir)-1] != '/') {
+ $dir .= '/';
+ }
+
+ return $dir . $filename;
+ }
+
+ static function url($filename)
+ {
+ $path = common_config('attachments', 'path');
+
+ if ($path[strlen($path)-1] != '/') {
+ $path .= '/';
+ }
+
+ if ($path[0] != '/') {
+ $path = '/'.$path;
+ }
+
+ $server = common_config('attachments', 'server');
+
+ if (empty($server)) {
+ $server = common_config('site', 'server');
+ }
+
+ // XXX: protocol
+
+ return 'http://'.$server.$path.$filename;
+ }
}
diff --git a/classes/File_oembed.php b/classes/File_oembed.php
index 2e8e851cd..69230e4a4 100644
--- a/classes/File_oembed.php
+++ b/classes/File_oembed.php
@@ -25,32 +25,36 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
* Table Definition for file_oembed
*/
-class File_oembed extends Memcached_DataObject
+class File_oembed extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'file_oembed'; // table name
- public $id; // int(11) not_null primary_key group_by
- public $file_id; // int(11) unique_key group_by
- public $version; // varchar(20)
- public $type; // varchar(20)
- public $provider; // varchar(50)
- public $provider_url; // varchar(255)
- public $width; // int(11) group_by
- public $height; // int(11) group_by
- public $html; // blob(65535) blob
- public $title; // varchar(255)
- public $author_name; // varchar(50)
- public $author_url; // varchar(255)
- public $url; // varchar(255)
+ public $file_id; // int(4) primary_key not_null
+ public $version; // varchar(20)
+ public $type; // varchar(20)
+ public $provider; // varchar(50)
+ public $provider_url; // varchar(255)
+ public $width; // int(4)
+ public $height; // int(4)
+ public $html; // text()
+ public $title; // varchar(255)
+ public $author_name; // varchar(50)
+ public $author_url; // varchar(255)
+ public $url; // varchar(255)
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_oembed',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('File_oembed',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ function sequenceKey()
+ {
+ return array(false, false, false);
+ }
function _getOembed($url, $maxwidth = 500, $maxheight = 400, $format = 'json') {
$cmd = common_config('oohembed', 'endpoint') . '?url=' . urlencode($url);
@@ -84,4 +88,3 @@ class File_oembed extends Memcached_DataObject
}
}
-
diff --git a/classes/File_redirection.php b/classes/File_redirection.php
index 0d6e2a700..d6fa0bcb6 100644
--- a/classes/File_redirection.php
+++ b/classes/File_redirection.php
@@ -25,31 +25,28 @@ require_once INSTALLDIR.'/classes/File_oembed.php';
define('USER_AGENT', 'Laconica user agent / file probe');
-
/**
* Table Definition for file_redirection
*/
-class File_redirection extends Memcached_DataObject
+class File_redirection extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'file_redirection'; // table name
- public $id; // int(11) not_null primary_key group_by
- public $url; // varchar(255) unique_key
- public $file_id; // int(11) group_by
- public $redirections; // int(11) group_by
- public $httpcode; // int(11) group_by
+ public $url; // varchar(255) primary_key not_null
+ public $file_id; // int(4)
+ public $redirections; // int(4)
+ public $httpcode; // int(4)
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_redirection',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('File_redirection',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
-
function _commonCurl($url, $redirs) {
$curlh = curl_init();
curl_setopt($curlh, CURLOPT_URL, $url);
@@ -69,24 +66,18 @@ class File_redirection extends Memcached_DataObject
// let's see if we know this...
$a = File::staticGet('url', $short_url);
- if (empty($a->id)) {
+
+ if (!empty($a)) {
+ // this is a direct link to $a->url
+ return $a->url;
+ } else {
$b = File_redirection::staticGet('url', $short_url);
- if (empty($b->id)) {
- // we'll have to figure it out
- } else {
+ if (!empty($b)) {
// this is a redirect to $b->file_id
- $a = File::staticGet($b->file_id);
- $url = $a->url;
+ $a = File::staticGet('id', $b->file_id);
+ return $a->url;
}
- } else {
- // this is a direct link to $a->url
- $url = $a->url;
}
- if (isset($url)) {
- return $url;
- }
-
-
$curlh = File_redirection::_commonCurl($short_url, $redirs);
// Don't include body in output
@@ -123,83 +114,22 @@ class File_redirection extends Memcached_DataObject
}
function makeShort($long_url) {
- $long_url = File_redirection::_canonUrl($long_url);
- // do we already know this long_url and have a short redirection for it?
- $file = new File;
- $file_redir = new File_redirection;
- $file->url = $long_url;
- $file->joinAdd($file_redir);
- $file->selectAdd('length(file_redirection.url) as len');
- $file->limit(1);
- $file->orderBy('len');
- $file->find(true);
- if (!empty($file->url) && (strlen($file->url) < strlen($long_url))) {
- return $file->url;
- }
-
- // if yet unknown, we must find a short url according to user settings
- $short_url = File_redirection::_userMakeShort($long_url, common_current_user());
- return $short_url;
- }
-
- function _userMakeShort($long_url, $user) {
- if (empty($user)) {
- // common current user does not find a user when called from the XMPP daemon
- // therefore we'll set one here fix, so that XMPP given URLs may be shortened
- $user->urlshorteningservice = 'ur1.ca';
- }
- $curlh = curl_init();
- curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait
- curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica');
- curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
- switch($user->urlshorteningservice) {
- case 'ur1.ca':
- require_once INSTALLDIR.'/lib/Shorturl_api.php';
- $short_url_service = new LilUrl;
- $short_url = $short_url_service->shorten($long_url);
- break;
+ $canon = File_redirection::_canonUrl($long_url);
- case '2tu.us':
- $short_url_service = new TightUrl;
- require_once INSTALLDIR.'/lib/Shorturl_api.php';
- $short_url = $short_url_service->shorten($long_url);
- break;
+ $short_url = File_redirection::_userMakeShort($canon);
- case 'ptiturl.com':
- require_once INSTALLDIR.'/lib/Shorturl_api.php';
- $short_url_service = new PtitUrl;
- $short_url = $short_url_service->shorten($long_url);
- break;
-
- case 'bit.ly':
- curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($long_url));
- $short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl;
- break;
-
- case 'is.gd':
- curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($long_url));
- $short_url = curl_exec($curlh);
- break;
- case 'snipr.com':
- curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($long_url));
- $short_url = curl_exec($curlh);
- break;
- case 'metamark.net':
- curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($long_url));
- $short_url = curl_exec($curlh);
- break;
- case 'tinyurl.com':
- curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($long_url));
- $short_url = curl_exec($curlh);
- break;
- default:
- $short_url = false;
+ // Did we get one? Is it shorter?
+ if (!empty($short_url) && mb_strlen($short_url) < mb_strlen($long_url)) {
+ return $short_url;
+ } else {
+ return $long_url;
}
+ }
- curl_close($curlh);
-
- if ($short_url) {
+ function _userMakeShort($long_url) {
+ $short_url = common_shorten_url($long_url);
+ if (!empty($short_url) && $short_url != $long_url) {
$short_url = (string)$short_url;
// store it
$file = File::staticGet('url', $long_url);
@@ -222,7 +152,7 @@ class File_redirection extends Memcached_DataObject
}
return $short_url;
}
- return $long_url;
+ return null;
}
function _canonUrl($in_url, $default_scheme = 'http://') {
diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php
index 2908549da..44b92a2fa 100644
--- a/classes/File_thumbnail.php
+++ b/classes/File_thumbnail.php
@@ -25,24 +25,29 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
* Table Definition for file_thumbnail
*/
-class File_thumbnail extends Memcached_DataObject
+class File_thumbnail extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'file_thumbnail'; // table name
- public $id; // int(11) not_null primary_key group_by
- public $file_id; // int(11) unique_key group_by
+ public $file_id; // int(4) primary_key not_null
public $url; // varchar(255) unique_key
- public $width; // int(11) group_by
- public $height; // int(11) group_by
+ public $width; // int(4)
+ public $height; // int(4)
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_thumbnail',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('File_thumbnail',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ function sequenceKey()
+ {
+ return array(false, false, false);
+ }
+
function saveNew($data, $file_id) {
$tn = new File_thumbnail;
$tn->file_id = $file_id;
diff --git a/classes/File_to_post.php b/classes/File_to_post.php
index 9362faaae..d35febb77 100644
--- a/classes/File_to_post.php
+++ b/classes/File_to_post.php
@@ -25,18 +25,18 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
* Table Definition for file_to_post
*/
-class File_to_post extends Memcached_DataObject
+class File_to_post extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'file_to_post'; // table name
- public $id; // int(11) not_null primary_key group_by
- public $file_id; // int(11) multiple_key group_by
- public $post_id; // int(11) group_by
+ public $file_id; // int(4) primary_key not_null
+ public $post_id; // int(4) primary_key not_null
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_to_post',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('File_to_post',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
@@ -44,17 +44,27 @@ class File_to_post extends Memcached_DataObject
function processNew($file_id, $notice_id) {
static $seen = array();
if (empty($seen[$notice_id]) || !in_array($file_id, $seen[$notice_id])) {
- $f2p = new File_to_post;
- $f2p->file_id = $file_id;
- $f2p->post_id = $notice_id;
- $f2p->insert();
+
+ $f2p = File_to_post::pkeyGet(array('post_id' => $notice_id,
+ 'file_id' => $file_id));
+ if (empty($f2p)) {
+ $f2p = new File_to_post;
+ $f2p->file_id = $file_id;
+ $f2p->post_id = $notice_id;
+ $f2p->insert();
+ }
+
if (empty($seen[$notice_id])) {
$seen[$notice_id] = array($file_id);
} else {
$seen[$notice_id][] = $file_id;
}
}
+ }
+ function &pkeyGet($kv)
+ {
+ return Memcached_DataObject::pkeyGet('File_to_post', $kv);
}
}
diff --git a/classes/Foreign_user.php b/classes/Foreign_user.php
index 61727abe5..8b3e03dfb 100644
--- a/classes/Foreign_user.php
+++ b/classes/Foreign_user.php
@@ -4,42 +4,41 @@
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-class Foreign_user extends Memcached_DataObject
+class Foreign_user extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'foreign_user'; // table name
- public $id; // int(4) primary_key not_null
+ public $id; // bigint(8) primary_key not_null
public $service; // int(4) primary_key not_null
public $uri; // varchar(255) unique_key not_null
- public $nickname; // varchar(255)
+ public $nickname; // varchar(255)
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* Static get */
- function staticGet($k,$v=null)
- { return Memcached_DataObject::staticGet('Foreign_user',$k,$v); }
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Foreign_user',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
+
// XXX: This only returns a 1->1 single obj mapping. Change? Or make
// a getForeignUsers() that returns more than one? --Zach
- static function getForeignUser($id, $service) {
+ static function getForeignUser($id, $service) {
$fuser = new Foreign_user();
$fuser->whereAdd("service = $service");
$fuser->whereAdd("id = $id");
$fuser->limit(1);
-
+
if ($fuser->find()) {
$fuser->fetch();
return $fuser;
}
-
- return null;
+
+ return null;
}
-
+
function updateKeys(&$orig)
{
$parts = array();
@@ -68,5 +67,4 @@ class Foreign_user extends Memcached_DataObject
return $result;
}
-
}
diff --git a/classes/Group_inbox.php b/classes/Group_inbox.php
index b80ba4272..1af7439f7 100644
--- a/classes/Group_inbox.php
+++ b/classes/Group_inbox.php
@@ -14,8 +14,14 @@ class Group_inbox extends Memcached_DataObject
public $created; // datetime() not_null
/* Static get */
+
function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Group_inbox',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+
+ function &pkeyGet($kv)
+ {
+ return Memcached_DataObject::pkeyGet('Group_inbox', $kv);
+ }
}
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index 2d5a73554..f7cbb9d5b 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -193,7 +193,14 @@ class Memcached_DataObject extends DB_DataObject
// unable to connect to sphinx' search daemon
if (!$connected) {
if ('mysql' === common_config('db', 'type')) {
- $search_engine = new MySQLSearch($this, $table);
+ $type = common_config('search', 'type');
+ if ($type == 'like') {
+ $search_engine = new MySQLLikeSearch($this, $table);
+ } else if ($type == 'fulltext') {
+ $search_engine = new MySQLSearch($this, $table);
+ } else {
+ throw new ServerException('Unknown search type: ' . $type);
+ }
} else {
$search_engine = new PGSearch($this, $table);
}
diff --git a/classes/Notice.php b/classes/Notice.php
index b6bbf66ca..8a018068a 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -34,6 +34,8 @@ define('NOTICE_REMOTE_OMB', 0);
define('NOTICE_LOCAL_NONPUBLIC', -1);
define('NOTICE_GATEWAY', -2);
+define('MAX_BOXCARS', 128);
+
class Notice extends Memcached_DataObject
{
###START_AUTOCODE
@@ -221,7 +223,7 @@ class Notice extends Memcached_DataObject
$notice->saveTags();
$notice->addToInboxes();
- $notice->saveGroups();
+
$notice->saveUrls();
$orig2 = clone($notice);
$notice->rendered = common_render_content($final, $notice);
@@ -331,6 +333,20 @@ class Notice extends Memcached_DataObject
return $n_attachments;
}
+ function attachments() {
+ // XXX: cache this
+ $att = array();
+ $f2p = new File_to_post;
+ $f2p->post_id = $this->id;
+ if ($f2p->find()) {
+ while ($f2p->fetch()) {
+ $f = File::staticGet($f2p->file_id);
+ $att[] = clone($f);
+ }
+ }
+ return $att;
+ }
+
function blowCaches($blowLast=false)
{
$this->blowSubsCache($blowLast);
@@ -339,6 +355,19 @@ class Notice extends Memcached_DataObject
$this->blowPublicCache($blowLast);
$this->blowTagCache($blowLast);
$this->blowGroupCache($blowLast);
+ $this->blowConversationCache($blowLast);
+ }
+
+ function blowConversationCache($blowLast=false)
+ {
+ $cache = common_memcache();
+ if ($cache) {
+ $ck = common_cache_key('notice:conversation_ids:'.$this->conversation);
+ $cache->delete($ck);
+ if ($blowLast) {
+ $cache->delete($ck.';last');
+ }
+ }
}
function blowGroupCache($blowLast=false)
@@ -471,8 +500,10 @@ class Notice extends Memcached_DataObject
if ($fave->find()) {
while ($fave->fetch()) {
$cache->delete(common_cache_key('fave:ids_by_user:'.$fave->user_id));
+ $cache->delete(common_cache_key('fave:by_user_own:'.$fave->user_id));
if ($blowLast) {
$cache->delete(common_cache_key('fave:ids_by_user:'.$fave->user_id.';last'));
+ $cache->delete(common_cache_key('fave:by_user_own:'.$fave->user_id.';last'));
}
}
}
@@ -675,7 +706,10 @@ class Notice extends Memcached_DataObject
if (!empty($cache)) {
$notices = array();
foreach ($ids as $id) {
- $notices[] = Notice::staticGet('id', $id);
+ $n = Notice::staticGet('id', $id);
+ if (!empty($n)) {
+ $notices[] = $n;
+ }
}
return new ArrayWrapper($notices);
} else {
@@ -744,34 +778,148 @@ class Notice extends Memcached_DataObject
return $ids;
}
+ function conversationStream($id, $offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
+ {
+ $ids = Notice::stream(array('Notice', '_conversationStreamDirect'),
+ array($id),
+ 'notice:conversation_ids:'.$id,
+ $offset, $limit, $since_id, $max_id, $since);
+
+ return Notice::getStreamByIds($ids);
+ }
+
+ function _conversationStreamDirect($id, $offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
+ {
+ $notice = new Notice();
+
+ $notice->selectAdd(); // clears it
+ $notice->selectAdd('id');
+
+ $notice->conversation = $id;
+
+ $notice->orderBy('id DESC');
+
+ if (!is_null($offset)) {
+ $notice->limit($offset, $limit);
+ }
+
+ if ($since_id != 0) {
+ $notice->whereAdd('id > ' . $since_id);
+ }
+
+ if ($max_id != 0) {
+ $notice->whereAdd('id <= ' . $max_id);
+ }
+
+ if (!is_null($since)) {
+ $notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
+ }
+
+ $ids = array();
+
+ if ($notice->find()) {
+ while ($notice->fetch()) {
+ $ids[] = $notice->id;
+ }
+ }
+
+ $notice->free();
+ $notice = NULL;
+
+ return $ids;
+ }
+
function addToInboxes()
{
$enabled = common_config('inboxes', 'enabled');
if ($enabled === true || $enabled === 'transitional') {
+
+ // XXX: loads constants
+
$inbox = new Notice_inbox();
- $UT = common_config('db','type')=='pgsql'?'"user"':'user';
- $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
- "SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " .
- "FROM $UT JOIN subscription ON $UT.id = subscription.subscriber " .
- 'WHERE subscription.subscribed = ' . $this->profile_id . ' ' .
- 'AND NOT EXISTS (SELECT user_id, notice_id ' .
- 'FROM notice_inbox ' .
- "WHERE user_id = $UT.id " .
- 'AND notice_id = ' . $this->id . ' )';
- if ($enabled === 'transitional') {
- $qry .= " AND $UT.inboxed = 1";
+
+ $users = $this->getSubscribedUsers();
+
+ // FIXME: kind of ignoring 'transitional'...
+ // we'll probably stop supporting inboxless mode
+ // in 0.9.x
+
+ $ni = array();
+
+ foreach ($users as $id) {
+ $ni[$id] = NOTICE_INBOX_SOURCE_SUB;
+ }
+
+ $groups = $this->saveGroups();
+
+ foreach ($groups as $group) {
+ $users = $group->getUserMembers();
+ foreach ($users as $id) {
+ if (!array_key_exists($id, $ni)) {
+ $ni[$id] = NOTICE_INBOX_SOURCE_GROUP;
+ }
+ }
+ }
+
+ $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.', '.$this->id.', '.$source.', "'.$this->created.'") ';
+ $cnt++;
+ if ($cnt >= MAX_BOXCARS) {
+ $inbox = new Notice_inbox();
+ $inbox->query($qry);
+ $qry = $qryhdr;
+ $cnt = 0;
+ }
+ }
+
+ if ($cnt > 0) {
+ $inbox = new Notice_inbox();
+ $inbox->query($qry);
}
- $inbox->query($qry);
}
+
return;
}
+ function getSubscribedUsers()
+ {
+ $user = new User();
+
+ $qry =
+ 'SELECT id ' .
+ 'FROM user JOIN subscription '.
+ 'ON user.id = subscription.subscriber ' .
+ 'WHERE subscription.subscribed = %d ';
+
+ $user->query(sprintf($qry, $this->profile_id));
+
+ $ids = array();
+
+ while ($user->fetch()) {
+ $ids[] = $user->id;
+ }
+
+ $user->free();
+
+ return $ids;
+ }
+
function saveGroups()
{
+ $groups = array();
+
$enabled = common_config('inboxes', 'enabled');
if ($enabled !== true && $enabled !== 'transitional') {
- return;
+ return $groups;
}
/* extract all !group */
@@ -779,7 +927,7 @@ class Notice extends Memcached_DataObject
strtolower($this->content),
$match);
if (!$count) {
- return true;
+ return $groups;
}
$profile = $this->getProfile();
@@ -805,41 +953,36 @@ class Notice extends Memcached_DataObject
if ($profile->isMember($group)) {
- $gi = new Group_inbox();
-
- $gi->group_id = $group->id;
- $gi->notice_id = $this->id;
- $gi->created = common_sql_now();
-
- $result = $gi->insert();
+ $result = $this->addToGroupInbox($group);
if (!$result) {
common_log_db_error($gi, 'INSERT', __FILE__);
}
- // FIXME: do this in an offline daemon
-
- $this->addToGroupInboxes($group);
+ $groups[] = clone($group);
}
}
+
+ return $groups;
}
- function addToGroupInboxes($group)
+ function addToGroupInbox($group)
{
- $inbox = new Notice_inbox();
- $UT = common_config('db','type')=='pgsql'?'"user"':'user';
- $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' .
- "SELECT $UT.id, " . $this->id . ", '" . $this->created . "', " . NOTICE_INBOX_SOURCE_GROUP . " " .
- "FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " .
- 'WHERE group_member.group_id = ' . $group->id . ' ' .
- 'AND NOT EXISTS (SELECT user_id, notice_id ' .
- 'FROM notice_inbox ' .
- "WHERE user_id = $UT.id " .
- 'AND notice_id = ' . $this->id . ' )';
- if ($enabled === 'transitional') {
- $qry .= " AND $UT.inboxed = 1";
- }
- $result = $inbox->query($qry);
+ $gi = Group_inbox::pkeyGet(array('group_id' => $group->id,
+ 'notice_id' => $this->id));
+
+ if (empty($gi)) {
+
+ $gi = new Group_inbox();
+
+ $gi->group_id = $group->id;
+ $gi->notice_id = $this->id;
+ $gi->created = $this->created;
+
+ return $gi->insert();
+ }
+
+ return true;
}
function saveReplies()
@@ -1044,6 +1187,7 @@ class Notice extends Memcached_DataObject
if (empty($cache) ||
$since_id != 0 || $max_id != 0 || (!is_null($since) && $since > 0) ||
+ is_null($limit) ||
($offset + $limit) > NOTICE_CACHE_WINDOW) {
return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id,
$max_id, $since)));
diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php
index 4ca2e9ae3..940381f84 100644
--- a/classes/Notice_inbox.php
+++ b/classes/Notice_inbox.php
@@ -27,6 +27,7 @@ define('INBOX_CACHE_WINDOW', 101);
define('NOTICE_INBOX_SOURCE_SUB', 1);
define('NOTICE_INBOX_SOURCE_GROUP', 2);
+define('NOTICE_INBOX_SOURCE_REPLY', 3);
define('NOTICE_INBOX_SOURCE_GATEWAY', -1);
class Notice_inbox extends Memcached_DataObject
diff --git a/classes/Profile.php b/classes/Profile.php
index 6b27c80cb..a0ed6b3ca 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -289,4 +289,52 @@ class Profile extends Memcached_DataObject
return Avatar::defaultImage($size);
}
}
+
+ function getSubscriptions($offset=0, $limit=null)
+ {
+ $qry =
+ 'SELECT profile.* ' .
+ 'FROM profile JOIN subscription ' .
+ 'ON profile.id = subscription.subscribed ' .
+ 'WHERE subscription.subscriber = %d ' .
+ 'AND subscription.subscribed != subscription.subscriber ' .
+ 'ORDER BY subscription.created DESC ';
+
+ if (common_config('db','type') == 'pgsql') {
+ $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+ } else {
+ $qry .= ' LIMIT ' . $offset . ', ' . $limit;
+ }
+
+ $profile = new Profile();
+
+ $profile->query(sprintf($qry, $this->id));
+
+ return $profile;
+ }
+
+ function getSubscribers($offset=0, $limit=null)
+ {
+ $qry =
+ 'SELECT profile.* ' .
+ 'FROM profile JOIN subscription ' .
+ 'ON profile.id = subscription.subscriber ' .
+ 'WHERE subscription.subscribed = %d ' .
+ 'AND subscription.subscribed != subscription.subscriber ' .
+ 'ORDER BY subscription.created DESC ';
+
+ if ($offset) {
+ if (common_config('db','type') == 'pgsql') {
+ $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+ } else {
+ $qry .= ' LIMIT ' . $offset . ', ' . $limit;
+ }
+ }
+
+ $profile = new Profile();
+
+ $cnt = $profile->query(sprintf($qry, $this->id));
+
+ return $profile;
+ }
}
diff --git a/classes/Session.php b/classes/Session.php
new file mode 100644
index 000000000..93fd99baa
--- /dev/null
+++ b/classes/Session.php
@@ -0,0 +1,129 @@
+<?php
+/**
+ * Table Definition for session
+ *
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2009, Control Yourself, 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
+ * 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/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
+
+class Session extends Memcached_DataObject
+{
+ ###START_AUTOCODE
+ /* the code below is auto generated do not remove the above tag */
+
+ public $__table = 'session'; // table name
+ public $id; // varchar(32) primary_key not_null
+ public $session_data; // text()
+ public $created; // datetime() not_null
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Session',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+ static function logdeb($msg)
+ {
+ if (common_config('sessions', 'debug')) {
+ common_debug("Session: " . $msg);
+ }
+ }
+
+ static function open($save_path, $session_name)
+ {
+ return true;
+ }
+
+ static function close()
+ {
+ return true;
+ }
+
+ static function read($id)
+ {
+ self::logdeb("Fetching session '$id'");
+
+ $session = Session::staticGet('id', $id);
+
+ if (empty($session)) {
+ return '';
+ } else {
+ return (string)$session->session_data;
+ }
+ }
+
+ static function write($id, $session_data)
+ {
+ self::logdeb("Writing session '$id'");
+
+ $session = Session::staticGet('id', $id);
+
+ if (empty($session)) {
+ $session = new Session();
+
+ $session->id = $id;
+ $session->session_data = $session_data;
+ $session->created = common_sql_now();
+
+ return $session->insert();
+ } else {
+ $session->session_data = $session_data;
+
+ return $session->update();
+ }
+ }
+
+ static function destroy($id)
+ {
+ self::logdeb("Deleting session $id");
+
+ $session = Session::staticGet('id', $id);
+
+ if (!empty($session)) {
+ return $session->delete();
+ }
+ }
+
+ static function gc($maxlifetime)
+ {
+ self::logdeb("garbage collection (maxlifetime = $maxlifetime)");
+
+ $epoch = time() - $maxlifetime;
+
+ $qry = 'DELETE FROM session ' .
+ 'WHERE modified < "'.$epoch.'"';
+
+ $session = new Session();
+
+ $result = $session->query($qry);
+
+ self::logdeb("garbage collection result = $result");
+ }
+
+ static function setSaveHandler()
+ {
+ self::logdeb("setting save handlers");
+ $result = session_set_save_handler('Session::open', 'Session::close', 'Session::read',
+ 'Session::write', 'Session::destroy', 'Session::gc');
+ self::logdeb("save handlers result = $result");
+ return $result;
+ }
+}
diff --git a/classes/Status_network.php b/classes/Status_network.php
index f8d6756b6..dbd722e88 100644
--- a/classes/Status_network.php
+++ b/classes/Status_network.php
@@ -132,6 +132,13 @@ class Status_network extends DB_DataObject
}
} else {
$sn = self::memGet('hostname', strtolower($servername));
+
+ if (empty($sn)) {
+ // Try for a no-www address
+ if (0 == strncasecmp($servername, 'www.', 4)) {
+ $sn = self::memGet('hostname', strtolower(substr($servername, 4)));
+ }
+ }
}
if (!empty($sn)) {
diff --git a/classes/User.php b/classes/User.php
index e8c8c5a75..04b38a0d2 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -424,9 +424,9 @@ class User extends Memcached_DataObject
}
}
- function favoriteNotices($offset=0, $limit=NOTICES_PER_PAGE)
+ function favoriteNotices($offset=0, $limit=NOTICES_PER_PAGE, $own=false)
{
- $ids = Fave::stream($this->id, $offset, $limit);
+ $ids = Fave::stream($this->id, $offset, $limit, $own);
return Notice::getStreamByIds($ids);
}
@@ -491,6 +491,8 @@ class User extends Memcached_DataObject
// ;last cache, too
$cache->delete(common_cache_key('fave:ids_by_user:'.$this->id));
$cache->delete(common_cache_key('fave:ids_by_user:'.$this->id.';last'));
+ $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id));
+ $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last'));
}
}
@@ -600,50 +602,16 @@ class User extends Memcached_DataObject
function getSubscriptions($offset=0, $limit=null)
{
- $qry =
- 'SELECT profile.* ' .
- 'FROM profile JOIN subscription ' .
- 'ON profile.id = subscription.subscribed ' .
- 'WHERE subscription.subscriber = %d ' .
- 'AND subscription.subscribed != subscription.subscriber ' .
- 'ORDER BY subscription.created DESC ';
-
- if (common_config('db','type') == 'pgsql') {
- $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
- } else {
- $qry .= ' LIMIT ' . $offset . ', ' . $limit;
- }
-
- $profile = new Profile();
-
- $profile->query(sprintf($qry, $this->id));
-
- return $profile;
+ $profile = $this->getProfile();
+ assert(!empty($profile));
+ return $profile->getSubscriptions($offset, $limit);
}
function getSubscribers($offset=0, $limit=null)
{
- $qry =
- 'SELECT profile.* ' .
- 'FROM profile JOIN subscription ' .
- 'ON profile.id = subscription.subscriber ' .
- 'WHERE subscription.subscribed = %d ' .
- 'AND subscription.subscribed != subscription.subscriber ' .
- 'ORDER BY subscription.created DESC ';
-
- if ($offset) {
- if (common_config('db','type') == 'pgsql') {
- $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
- } else {
- $qry .= ' LIMIT ' . $offset . ', ' . $limit;
- }
- }
-
- $profile = new Profile();
-
- $cnt = $profile->query(sprintf($qry, $this->id));
-
- return $profile;
+ $profile = $this->getProfile();
+ assert(!empty($profile));
+ return $profile->getSubscribers($offset, $limit);
}
function getTaggedSubscribers($tag, $offset=0, $limit=null)
diff --git a/classes/User_group.php b/classes/User_group.php
index 8a56b9e52..27b444705 100644
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -126,6 +126,30 @@ class User_group extends Memcached_DataObject
return $members;
}
+ function getAdmins($offset=0, $limit=null)
+ {
+ $qry =
+ 'SELECT profile.* ' .
+ 'FROM profile JOIN group_member '.
+ 'ON profile.id = group_member.profile_id ' .
+ 'WHERE group_member.group_id = %d ' .
+ 'AND group_member.is_admin = 1 ' .
+ 'ORDER BY group_member.modified ASC ';
+
+ if ($limit != null) {
+ if (common_config('db','type') == 'pgsql') {
+ $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+ } else {
+ $qry .= ' LIMIT ' . $offset . ', ' . $limit;
+ }
+ }
+
+ $admins = new Profile();
+
+ $admins->query(sprintf($qry, $this->id));
+ return $admins;
+ }
+
function getBlocked($offset=0, $limit=null)
{
$qry =
@@ -246,4 +270,28 @@ class User_group extends Memcached_DataObject
return Design::staticGet('id', $this->design_id);
}
+ function getUserMembers()
+ {
+ // XXX: cache this
+
+ $user = new User();
+
+ $qry =
+ 'SELECT id ' .
+ 'FROM user JOIN group_member '.
+ 'ON user.id = group_member.profile_id ' .
+ 'WHERE group_member.group_id = %d ';
+
+ $user->query(sprintf($qry, $this->id));
+
+ $ids = array();
+
+ while ($user->fetch()) {
+ $ids[] = $user->id;
+ }
+
+ $user->free();
+
+ return $ids;
+ }
}
diff --git a/classes/laconica.ini b/classes/laconica.ini
index 5ced15885..766bed75d 100755..100644
--- a/classes/laconica.ini
+++ b/classes/laconica.ini
@@ -68,13 +68,14 @@ size = 1
title = 2
date = 1
protected = 1
+filename = 2
+modified = 384
[file__keys]
id = N
[file_oembed]
-id = 129
-file_id = 1
+file_id = 129
version = 2
type = 2
provider = 2
@@ -86,37 +87,40 @@ title = 2
author_name = 2
author_url = 2
url = 2
+modified = 384
[file_oembed__keys]
-id = N
+file_id = K
[file_redirection]
-id = 129
-url = 2
+url = 130
file_id = 1
redirections = 1
httpcode = 1
+modified = 384
[file_redirection__keys]
-id = N
+url = K
[file_thumbnail]
-id = 129
-file_id = 1
+file_id = 129
url = 2
width = 1
height = 1
+modified = 384
[file_thumbnail__keys]
-id = N
+file_id = K
+url = U
[file_to_post]
-id = 129
-file_id = 1
-post_id = 1
+file_id = 129
+post_id = 129
+modified = 384
[file_to_post__keys]
-id = N
+file_id = K
+post_id = K
[foreign_link]
user_id = 129
@@ -376,6 +380,15 @@ replied_id = 1
notice_id = K
profile_id = K
+[session]
+id = 130
+session_data = 34
+created = 142
+modified = 384
+
+[session__keys]
+id = K
+
[sms_carrier]
id = 129
name = 2