summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/File.php149
-rw-r--r--classes/File_oembed.php87
-rw-r--r--classes/File_redirection.php274
-rw-r--r--classes/File_thumbnail.php55
-rw-r--r--classes/File_to_post.php60
-rw-r--r--classes/Foreign_link.php12
-rw-r--r--[-rwxr-xr-x]classes/Group_inbox.php0
-rw-r--r--[-rwxr-xr-x]classes/Group_member.php0
-rw-r--r--classes/Notice.php55
-rw-r--r--classes/Notice_inbox.php5
-rw-r--r--classes/Profile.php54
-rw-r--r--[-rwxr-xr-x]classes/Related_group.php0
-rw-r--r--classes/Status_network.php61
-rw-r--r--classes/User.php11
-rw-r--r--[-rwxr-xr-x]classes/User_group.php0
-rw-r--r--[-rwxr-xr-x]classes/laconica.ini60
-rw-r--r--classes/laconica.links.ini14
-rwxr-xr-xclasses/statusnet.ini17
18 files changed, 902 insertions, 12 deletions
diff --git a/classes/File.php b/classes/File.php
new file mode 100644
index 000000000..24ab11b8e
--- /dev/null
+++ b/classes/File.php
@@ -0,0 +1,149 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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';
+require_once INSTALLDIR.'/classes/File_redirection.php';
+require_once INSTALLDIR.'/classes/File_oembed.php';
+require_once INSTALLDIR.'/classes/File_thumbnail.php';
+require_once INSTALLDIR.'/classes/File_to_post.php';
+//require_once INSTALLDIR.'/classes/File_redirection.php';
+
+/**
+ * Table Definition for file
+ */
+
+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 $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
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+ function isProtected($url) {
+ return 'http://www.facebook.com/login.php' === $url;
+ }
+
+ function getAttachments($post_id) {
+ $query = "select file.* from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $this->escape($post_id);
+ $this->query($query);
+ $att = array();
+ while ($this->fetch()) {
+ $att[] = clone($this);
+ }
+ $this->free();
+ return $att;
+ }
+
+ function saveNew($redir_data, $given_url) {
+ $x = new File;
+ $x->url = $given_url;
+ if (!empty($redir_data['protected'])) $x->protected = $redir_data['protected'];
+ if (!empty($redir_data['title'])) $x->title = $redir_data['title'];
+ if (!empty($redir_data['type'])) $x->mimetype = $redir_data['type'];
+ if (!empty($redir_data['size'])) $x->size = intval($redir_data['size']);
+ if (isset($redir_data['time']) && $redir_data['time'] > 0) $x->date = intval($redir_data['time']);
+ $file_id = $x->insert();
+
+ if (isset($redir_data['type'])
+ && ('text/html' === substr($redir_data['type'], 0, 9))
+ && ($oembed_data = File_oembed::_getOembed($given_url))
+ && isset($oembed_data['json'])) {
+
+ File_oembed::saveNew($oembed_data['json'], $file_id);
+ }
+ return $x;
+ }
+
+ function processNew($given_url, $notice_id) {
+ if (empty($given_url)) return -1; // error, no url to process
+ $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)) {
+ $file_redir = File_redirection::staticGet('url', $given_url);
+ if (empty($file_redir->id)) {
+ $redir_data = File_redirection::where($given_url);
+ $redir_url = $redir_data['url'];
+ if ($redir_url === $given_url) {
+ $x = File::saveNew($redir_data, $given_url);
+ $file_id = $x->id;
+
+ } else {
+ $x = File::processNew($redir_url, $notice_id);
+ $file_id = $x->id;
+ File_redirection::saveNew($redir_data, $file_id, $given_url);
+ }
+ } else {
+ $file_id = $file_redir->file_id;
+ }
+ } else {
+ $file_id = $file->id;
+ $x = $file;
+ }
+
+ if (empty($x)) {
+ $x = File::staticGet($file_id);
+ if (empty($x)) die('Impossible!');
+ }
+
+ File_to_post::processNew($file_id, $notice_id);
+ return $x;
+ }
+
+ 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']);
+ }
+
+ $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'";
+ $this->query($query);
+ $this->fetch();
+ $total = $this->total + $_FILES['attach']['size'];
+ if ($total > common_config('attachments', 'user_quota')) {
+ return sprintf(_('A file this large would exceed your user quota of %d bytes.'), common_config('attachments', 'user_quota'));
+ }
+
+ $query .= ' month(modified) = month(now()) and year(modified) = year(now())';
+ $this->query($query);
+ $this->fetch();
+ $total = $this->total + $_FILES['attach']['size'];
+ if ($total > common_config('attachments', 'monthly_quota')) {
+ return sprintf(_('A file this large would exceed your monthly quota of %d bytes.'), common_config('attachments', 'monthly_quota'));
+ }
+ return true;
+ }
+}
+
diff --git a/classes/File_oembed.php b/classes/File_oembed.php
new file mode 100644
index 000000000..f1b2cb13c
--- /dev/null
+++ b/classes/File_oembed.php
@@ -0,0 +1,87 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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';
+
+/**
+ * Table Definition for file_oembed
+ */
+
+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)
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_oembed',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+
+ function _getOembed($url, $maxwidth = 500, $maxheight = 400, $format = 'json') {
+ $cmd = 'http://oohembed.com/oohembed/?url=' . urlencode($url);
+ if (is_int($maxwidth)) $cmd .= "&maxwidth=$maxwidth";
+ if (is_int($maxheight)) $cmd .= "&maxheight=$maxheight";
+ if (is_string($format)) $cmd .= "&format=$format";
+ $oe = @file_get_contents($cmd);
+ if (false === $oe) return false;
+ return array($format => (('json' === $format) ? json_decode($oe, true) : $oe));
+ }
+
+ function saveNew($data, $file_id) {
+ $file_oembed = new File_oembed;
+ $file_oembed->file_id = $file_id;
+ $file_oembed->version = $data['version'];
+ $file_oembed->type = $data['type'];
+ if (!empty($data['provider_name'])) $file_oembed->provider = $data['provider_name'];
+ if (!isset($file_oembed->provider) && !empty($data['provide'])) $file_oembed->provider = $data['provider'];
+ if (!empty($data['provide_url'])) $file_oembed->provider_url = $data['provider_url'];
+ if (!empty($data['width'])) $file_oembed->width = intval($data['width']);
+ if (!empty($data['height'])) $file_oembed->height = intval($data['height']);
+ if (!empty($data['html'])) $file_oembed->html = $data['html'];
+ if (!empty($data['title'])) $file_oembed->title = $data['title'];
+ if (!empty($data['author_name'])) $file_oembed->author_name = $data['author_name'];
+ if (!empty($data['author_url'])) $file_oembed->author_url = $data['author_url'];
+ if (!empty($data['url'])) $file_oembed->url = $data['url'];
+ $file_oembed->insert();
+ if (!empty($data['thumbnail_url'])) {
+ File_thumbnail::saveNew($data, $file_id);
+ }
+ }
+}
+
+
diff --git a/classes/File_redirection.php b/classes/File_redirection.php
new file mode 100644
index 000000000..212cc3615
--- /dev/null
+++ b/classes/File_redirection.php
@@ -0,0 +1,274 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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';
+require_once INSTALLDIR.'/classes/File.php';
+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
+{
+ ###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
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return DB_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);
+ curl_setopt($curlh, CURLOPT_AUTOREFERER, true); // # setup referer header when folowing redirects
+ curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 10); // # seconds to wait
+ curl_setopt($curlh, CURLOPT_MAXREDIRS, $redirs); // # max number of http redirections to follow
+ curl_setopt($curlh, CURLOPT_USERAGENT, USER_AGENT);
+ curl_setopt($curlh, CURLOPT_FOLLOWLOCATION, true); // Follow redirects
+ curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curlh, CURLOPT_FILETIME, true);
+ curl_setopt($curlh, CURLOPT_HEADER, true); // Include header in output
+ return $curlh;
+ }
+
+ function _redirectWhere_imp($short_url, $redirs = 10, $protected = false) {
+ if ($redirs < 0) return false;
+
+ // let's see if we know this...
+ $a = File::staticGet('url', $short_url);
+ if (empty($a->id)) {
+ $b = File_redirection::staticGet('url', $short_url);
+ if (empty($b->id)) {
+ // we'll have to figure it out
+ } else {
+ // this is a redirect to $b->file_id
+ $a = File::staticGet($b->file_id);
+ $url = $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
+ curl_setopt($curlh, CURLOPT_NOBODY, true);
+ curl_exec($curlh);
+ $info = curl_getinfo($curlh);
+ curl_close($curlh);
+
+ if (405 == $info['http_code']) {
+ $curlh = File_redirection::_commonCurl($short_url, $redirs);
+ curl_exec($curlh);
+ $info = curl_getinfo($curlh);
+ curl_close($curlh);
+ }
+
+ if (!empty($info['redirect_count']) && File::isProtected($info['url'])) {
+ return File_redirection::_redirectWhere_imp($short_url, $info['redirect_count'] - 1, true);
+ }
+
+ $ret = array('code' => $info['http_code']
+ , 'redirects' => $info['redirect_count']
+ , 'url' => $info['url']);
+
+ if (!empty($info['content_type'])) $ret['type'] = $info['content_type'];
+ if ($protected) $ret['protected'] = true;
+ if (!empty($info['download_content_length'])) $ret['size'] = $info['download_content_length'];
+ if (isset($info['filetime']) && ($info['filetime'] > 0)) $ret['time'] = $info['filetime'];
+ return $ret;
+ }
+
+ function where($in_url) {
+ $ret = File_redirection::_redirectWhere_imp($in_url);
+ return $ret;
+ }
+
+ 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;
+
+ case '2tu.us':
+ $short_url_service = new TightUrl;
+ require_once INSTALLDIR.'/lib/Shorturl_api.php';
+ $short_url = $short_url_service->shorten($long_url);
+ break;
+
+ 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;
+ }
+
+ curl_close($curlh);
+
+ if ($short_url) {
+ $short_url = (string)$short_url;
+ // store it
+ $file = File::staticGet('url', $long_url);
+ if (empty($file)) {
+ $redir_data = File_redirection::where($long_url);
+ $file = File::saveNew($redir_data, $long_url);
+ $file_id = $file->id;
+ if (!empty($redir_data['oembed']['json'])) {
+ File_oembed::saveNew($redir_data['oembed']['json'], $file_id);
+ }
+ } else {
+ $file_id = $file->id;
+ }
+ $file_redir = File_redirection::staticGet('url', $short_url);
+ if (empty($file_redir)) {
+ $file_redir = new File_redirection;
+ $file_redir->url = $short_url;
+ $file_redir->file_id = $file_id;
+ $file_redir->insert();
+ }
+ return $short_url;
+ }
+ return $long_url;
+ }
+
+ function _canonUrl($in_url, $default_scheme = 'http://') {
+ if (empty($in_url)) return false;
+ $out_url = $in_url;
+ $p = parse_url($out_url);
+ if (empty($p['host']) || empty($p['scheme'])) {
+ list($scheme) = explode(':', $in_url, 2);
+ switch ($scheme) {
+ case 'fax':
+ case 'tel':
+ $out_url = str_replace('.-()', '', $out_url);
+ break;
+
+ case 'mailto':
+ case 'aim':
+ case 'jabber':
+ case 'xmpp':
+ // don't touch anything
+ break;
+
+ default:
+ $out_url = $default_scheme . ltrim($out_url, '/');
+ $p = parse_url($out_url);
+ if (empty($p['scheme'])) return false;
+ break;
+ }
+ }
+
+ if (('ftp' == $p['scheme']) || ('http' == $p['scheme']) || ('https' == $p['scheme'])) {
+ if (empty($p['host'])) return false;
+ if (empty($p['path'])) {
+ $out_url .= '/';
+ }
+ }
+
+ return $out_url;
+ }
+
+ function saveNew($data, $file_id, $url) {
+ $file_redir = new File_redirection;
+ $file_redir->url = $url;
+ $file_redir->file_id = $file_id;
+ $file_redir->redirections = intval($data['redirects']);
+ $file_redir->httpcode = intval($data['code']);
+ $file_redir->insert();
+ }
+}
+
diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php
new file mode 100644
index 000000000..1a65b92c9
--- /dev/null
+++ b/classes/File_thumbnail.php
@@ -0,0 +1,55 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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';
+
+/**
+ * Table Definition for file_thumbnail
+ */
+
+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 $url; // varchar(255) unique_key
+ public $width; // int(11) group_by
+ public $height; // int(11) group_by
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_thumbnail',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+ function saveNew($data, $file_id) {
+ $tn = new File_thumbnail;
+ $tn->file_id = $file_id;
+ $tn->url = $data['thumbnail_url'];
+ $tn->width = intval($data['thumbnail_width']);
+ $tn->height = intval($data['thumbnail_height']);
+ $tn->insert();
+ }
+}
+
diff --git a/classes/File_to_post.php b/classes/File_to_post.php
new file mode 100644
index 000000000..00ddebe6b
--- /dev/null
+++ b/classes/File_to_post.php
@@ -0,0 +1,60 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, 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';
+
+/**
+ * Table Definition for file_to_post
+ */
+
+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
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_to_post',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+ 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();
+ if (empty($seen[$notice_id])) {
+ $seen[$notice_id] = array($file_id);
+ } else {
+ $seen[$notice_id][] = $file_id;
+ }
+ }
+
+ }
+}
+
diff --git a/classes/Foreign_link.php b/classes/Foreign_link.php
index af2b3f189..c0b356ece 100644
--- a/classes/Foreign_link.php
+++ b/classes/Foreign_link.php
@@ -11,7 +11,7 @@ class Foreign_link extends Memcached_DataObject
public $__table = 'foreign_link'; // table name
public $user_id; // int(4) primary_key not_null
- public $foreign_id; // int(4) primary_key not_null
+ public $foreign_id; // bigint(8) primary_key not_null unsigned
public $service; // int(4) primary_key not_null
public $credentials; // varchar(255)
public $noticesync; // tinyint(1) not_null default_1
@@ -59,13 +59,19 @@ class Foreign_link extends Memcached_DataObject
return null;
}
- function set_flags($noticesync, $replysync, $friendsync)
+ function set_flags($noticesend, $noticerecv, $replysync, $friendsync)
{
- if ($noticesync) {
+ if ($noticesend) {
$this->noticesync |= FOREIGN_NOTICE_SEND;
} else {
$this->noticesync &= ~FOREIGN_NOTICE_SEND;
}
+
+ if ($noticerecv) {
+ $this->noticesync |= FOREIGN_NOTICE_RECV;
+ } else {
+ $this->noticesync &= ~FOREIGN_NOTICE_RECV;
+ }
if ($replysync) {
$this->noticesync |= FOREIGN_NOTICE_SEND_REPLY;
diff --git a/classes/Group_inbox.php b/classes/Group_inbox.php
index b80ba4272..b80ba4272 100755..100644
--- a/classes/Group_inbox.php
+++ b/classes/Group_inbox.php
diff --git a/classes/Group_member.php b/classes/Group_member.php
index 3c23a991f..3c23a991f 100755..100644
--- a/classes/Group_member.php
+++ b/classes/Group_member.php
diff --git a/classes/Notice.php b/classes/Notice.php
index bca4b22c4..78786b27d 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -46,6 +46,7 @@ class Notice extends Memcached_DataObject
public $reply_to; // int(4)
public $is_local; // tinyint(1)
public $source; // varchar(32)
+ public $conversation; // int(4)
/* Static get */
function staticGet($k,$v=NULL) {
@@ -119,7 +120,8 @@ class Notice extends Memcached_DataObject
}
}
- static function saveNew($profile_id, $content, $source=null, $is_local=1, $reply_to=null, $uri=null) {
+ static function saveNew($profile_id, $content, $source=null,
+ $is_local=1, $reply_to=null, $uri=null, $created=null) {
$profile = Profile::staticGet($profile_id);
@@ -170,12 +172,24 @@ class Notice extends Memcached_DataObject
$notice->query('BEGIN');
$notice->reply_to = $reply_to;
- $notice->created = common_sql_now();
+ if (!empty($created)) {
+ $notice->created = $created;
+ } else {
+ $notice->created = common_sql_now();
+ }
$notice->content = $final;
$notice->rendered = common_render_content($final, $notice);
$notice->source = $source;
$notice->uri = $uri;
+ if (!empty($reply_to)) {
+ $reply_notice = Notice::staticGet('id', $reply_to);
+ if (!empty($reply_notice)) {
+ $notice->reply_to = $reply_to;
+ $notice->conversation = $reply_notice->conversation;
+ }
+ }
+
if (Event::handle('StartNoticeSave', array(&$notice))) {
$id = $notice->insert();
@@ -265,6 +279,30 @@ class Notice extends Memcached_DataObject
return true;
}
+ function getUploadedAttachment() {
+ $post = clone $this;
+ $query = 'select file.url as up, file.id as i from file join file_to_post on file.id = file_id where post_id=' . $post->escape($post->id) . ' and url like "%/notice/%/file"';
+ $post->query($query);
+ $post->fetch();
+ if (empty($post->up) || empty($post->i)) {
+ $ret = false;
+ } else {
+ $ret = array($post->up, $post->i);
+ }
+ $post->free();
+ return $ret;
+ }
+
+ function hasAttachments() {
+ $post = clone $this;
+ $query = "select count(file_id) as n_attachments from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $post->escape($post->id);
+ $post->query($query);
+ $post->fetch();
+ $n_attachments = intval($post->n_attachments);
+ $post->free();
+ return $n_attachments;
+ }
+
function blowCaches($blowLast=false)
{
$this->blowSubsCache($blowLast);
@@ -804,6 +842,7 @@ class Notice extends Memcached_DataObject
if ($recipient_notice) {
$orig = clone($this);
$this->reply_to = $recipient_notice->id;
+ $this->conversation = $recipient_notice->conversation;
$this->update($orig);
}
}
@@ -853,6 +892,14 @@ class Notice extends Memcached_DataObject
}
}
+ // If it's not a reply, make it the root of a new conversation
+
+ if (empty($this->conversation)) {
+ $orig = clone($this);
+ $this->conversation = $this->id;
+ $this->update($orig);
+ }
+
foreach (array_keys($replied) as $recipient) {
$user = User::staticGet('id', $recipient);
if ($user) {
@@ -983,7 +1030,7 @@ class Notice extends Memcached_DataObject
$window = explode(',', $laststr);
$last_id = $window[0];
$new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
- $last_id, 0, null)));
+ $last_id, 0, null, $tag)));
$new_window = array_merge($new_ids, $window);
@@ -998,7 +1045,7 @@ class Notice extends Memcached_DataObject
}
$window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
- 0, 0, null)));
+ 0, 0, null, $tag)));
$windowstr = implode(',', $window);
diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php
index 8a27e1747..673e187c7 100644
--- a/classes/Notice_inbox.php
+++ b/classes/Notice_inbox.php
@@ -85,4 +85,9 @@ class Notice_inbox extends Memcached_DataObject
return $ids;
}
+
+ function &pkeyGet($kv)
+ {
+ return Memcached_DataObject::pkeyGet('Notice_inbox', $kv);
+ }
}
diff --git a/classes/Profile.php b/classes/Profile.php
index 3d13cd46a..4a459b974 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -153,18 +153,66 @@ class Profile extends Memcached_DataObject
return null;
}
- function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
+ function getTaggedNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null, $tag=null)
+ {
+ // XXX: I'm not sure this is going to be any faster. It probably isn't.
+ $ids = Notice::stream(array($this, '_streamTaggedDirect'),
+ array(),
+ 'profile:notice_ids:' . $this->id,
+ $offset, $limit, $since_id, $before_id, $since, $tag);
+ common_debug(print_r($ids, true));
+ return Notice::getStreamByIds($ids);
+ }
+
+ function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
// XXX: I'm not sure this is going to be any faster. It probably isn't.
$ids = Notice::stream(array($this, '_streamDirect'),
array(),
'profile:notice_ids:' . $this->id,
- $offset, $limit, $since_id, $max_id);
+ $offset, $limit, $since_id, $max_id, $since);
return Notice::getStreamByIds($ids);
}
- function _streamDirect($offset, $limit, $since_id, $max_id, $since)
+ function _streamTaggedDirect($offset, $limit, $since_id, $before_id, $since=null, $tag=null)
+ {
+ common_debug('_streamTaggedDirect()');
+ $notice = new Notice();
+ $notice->profile_id = $this->id;
+ $query = "select id from notice join notice_tag on id=notice_id where tag='" . $notice->escape($tag) . "' and profile_id=" . $notice->escape($notice->profile_id);
+ if ($since_id != 0) {
+ $query .= " and id > $since_id";
+ }
+
+ if ($before_id != 0) {
+ $query .= " and id < $before_id";
+ }
+
+ if (!is_null($since)) {
+ $query .= " and created > '" . date('Y-m-d H:i:s', $since) . "'";
+ }
+
+ $query .= ' order by id DESC';
+
+ if (!is_null($offset)) {
+ $query .= " limit $offset, $limit";
+ }
+ $notice->query($query);
+ $ids = array();
+
+ while ($notice->fetch()) {
+ common_debug(print_r($notice, true));
+ $ids[] = $notice->id;
+ }
+
+ return $ids;
+ }
+
+
+
+
+ function _streamDirect($offset, $limit, $since_id, $before_id, $since = null)
{
$notice = new Notice();
diff --git a/classes/Related_group.php b/classes/Related_group.php
index c00ad9c44..c00ad9c44 100755..100644
--- a/classes/Related_group.php
+++ b/classes/Related_group.php
diff --git a/classes/Status_network.php b/classes/Status_network.php
new file mode 100644
index 000000000..f7747f71d
--- /dev/null
+++ b/classes/Status_network.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Table Definition for status_network
+ */
+
+class Status_network extends DB_DataObject
+{
+ ###START_AUTOCODE
+ /* the code below is auto generated do not remove the above tag */
+
+ public $__table = 'status_network'; // table name
+ public $nickname; // varchar(64) primary_key not_null
+ public $hostname; // varchar(255) unique_key
+ public $pathname; // varchar(255) unique_key
+ public $sitename; // varchar(255)
+ public $dbhost; // varchar(255)
+ public $dbuser; // varchar(255)
+ public $dbpass; // varchar(255)
+ public $dbname; // varchar(255)
+ public $created; // datetime() not_null
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Status_network',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+ static function setupDB($dbhost, $dbuser, $dbpass, $dbname)
+ {
+ global $config;
+
+ $config['db']['database_'.$dbname] = "mysqli://$dbuser:$dbpass@$dbhost/$dbname";
+ $config['db']['ini_'.$dbname] = INSTALLDIR.'/classes/statusnet.ini';
+ $config['db']['table_status_network'] = $dbname;
+
+ return true;
+ }
+
+ static function setupSite($servername, $pathname)
+ {
+ global $config;
+
+ $parts = explode('.', $servername);
+
+ $sn = Status_network::staticGet('nickname', $parts[0]);
+
+ if (!empty($sn)) {
+ $dbhost = (empty($sn->dbhost)) ? 'localhost' : $sn->dbhost;
+ $dbuser = (empty($sn->dbuser)) ? $sn->nickname : $sn->dbuser;
+ $dbpass = $sn->dbpass;
+ $dbname = (empty($sn->dbname)) ? $sn->nickname : $sn->dbname;
+
+ $config['db']['database'] = "mysqli://$dbuser:$dbpass@$dbhost/$dbname";
+ $config['site']['name'] = $sn->sitename;
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/classes/User.php b/classes/User.php
index 59451258e..08a166d5a 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -406,13 +406,22 @@ class User extends Memcached_DataObject
return Notice::getStreamByIds($ids);
}
+ function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) {
+ $profile = $this->getProfile();
+ if (!$profile) {
+ return null;
+ } else {
+ return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id, $since);
+ }
+ }
+
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
$profile = $this->getProfile();
if (!$profile) {
return null;
} else {
- return $profile->getNotices($offset, $limit, $since_id, $before_id);
+ return $profile->getNotices($offset, $limit, $since_id, $before_id, $since);
}
}
diff --git a/classes/User_group.php b/classes/User_group.php
index a135015ba..a135015ba 100755..100644
--- a/classes/User_group.php
+++ b/classes/User_group.php
diff --git a/classes/laconica.ini b/classes/laconica.ini
index c05419588..92bbb35d4 100755..100644
--- a/classes/laconica.ini
+++ b/classes/laconica.ini
@@ -1,4 +1,3 @@
-
[avatar]
profile_id = 129
original = 17
@@ -47,6 +46,64 @@ modified = 384
notice_id = K
user_id = K
+[file]
+id = 129
+url = 2
+mimetype = 2
+size = 1
+title = 2
+date = 1
+protected = 1
+
+[file__keys]
+id = N
+
+[file_oembed]
+id = 129
+file_id = 1
+version = 2
+type = 2
+provider = 2
+provider_url = 2
+width = 1
+height = 1
+html = 34
+title = 2
+author_name = 2
+author_url = 2
+url = 2
+
+[file_oembed__keys]
+id = N
+
+[file_redirection]
+id = 129
+url = 2
+file_id = 1
+redirections = 1
+httpcode = 1
+
+[file_redirection__keys]
+id = N
+
+[file_thumbnail]
+id = 129
+file_id = 1
+url = 2
+width = 1
+height = 1
+
+[file_thumbnail__keys]
+id = N
+
+[file_to_post]
+id = 129
+file_id = 1
+post_id = 1
+
+[file_to_post__keys]
+id = N
+
[foreign_link]
user_id = 129
foreign_id = 129
@@ -170,6 +227,7 @@ modified = 384
reply_to = 1
is_local = 17
source = 2
+conversation = 1
[notice__keys]
id = N
diff --git a/classes/laconica.links.ini b/classes/laconica.links.ini
index 173b18726..95c63f3c0 100644
--- a/classes/laconica.links.ini
+++ b/classes/laconica.links.ini
@@ -41,3 +41,17 @@ subscribed = profile:id
[fave]
notice_id = notice:id
user_id = user:id
+
+[file_oembed]
+file_id = file:id
+
+[file_redirection]
+file_id = file:id
+
+[file_thumbnail]
+file_id = file:id
+
+[file_to_post]
+file_id = file:id
+post_id = notice:id
+
diff --git a/classes/statusnet.ini b/classes/statusnet.ini
new file mode 100755
index 000000000..a70cd4122
--- /dev/null
+++ b/classes/statusnet.ini
@@ -0,0 +1,17 @@
+
+[status_network]
+nickname = 130
+hostname = 2
+pathname = 2
+sitename = 2
+dbhost = 2
+dbuser = 2
+dbpass = 2
+dbname = 2
+created = 142
+modified = 384
+
+[status_network__keys]
+nickname = K
+hostname = U
+pathname = U