summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/all.php8
-rw-r--r--actions/allrss.php8
-rw-r--r--actions/facebookhome.php58
-rw-r--r--classes/Notice.php2
-rw-r--r--classes/Notice_inbox.php13
-rw-r--r--classes/User.php29
-rwxr-xr-xscripts/twitterstatusfetcher.php111
7 files changed, 164 insertions, 65 deletions
diff --git a/actions/all.php b/actions/all.php
index 03179a246..80fc9d54b 100644
--- a/actions/all.php
+++ b/actions/all.php
@@ -98,7 +98,13 @@ class AllAction extends ProfileAction
function showContent()
{
- $notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+ $cur = common_current_user();
+
+ if (!empty($cur) && $cur->id == $this->user->id) {
+ $notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+ } else {
+ $notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+ }
$nl = new NoticeList($notice, $this);
diff --git a/actions/allrss.php b/actions/allrss.php
index 45f3946a6..88a4745c9 100644
--- a/actions/allrss.php
+++ b/actions/allrss.php
@@ -81,6 +81,14 @@ class AllrssAction extends Rss10Action
*/
function getNotices($limit=0)
{
+ $cur = common_current_user();
+
+ if (!empty($cur) && $cur->id == $user->id) {
+ $notice = $this->user->noticeInbox(0, $limit);
+ } else {
+ $notice = $this->user->noticesWithFriends(0, $limit);
+ }
+
$user = $this->user;
$notice = $user->noticesWithFriends(0, $limit);
$notices = array();
diff --git a/actions/facebookhome.php b/actions/facebookhome.php
index 00b35ef68..f74b786d1 100644
--- a/actions/facebookhome.php
+++ b/actions/facebookhome.php
@@ -21,29 +21,28 @@ if (!defined('LACONICA')) { exit(1); }
require_once INSTALLDIR.'/lib/facebookaction.php';
-
class FacebookhomeAction extends FacebookAction
{
var $page = null;
-
+
function prepare($argarray)
- {
+ {
parent::prepare($argarray);
-
+
$this->page = $this->trimmed('page');
-
+
if (!$this->page) {
$this->page = 1;
}
-
+
return true;
}
function handle($args)
{
- parent::handle($args);
-
+ parent::handle($args);
+
// If the user has opted not to initially allow the app to have
// Facebook status update permission, store that preference. Only
// promt the user the first time she uses the app
@@ -73,7 +72,7 @@ class FacebookhomeAction extends FacebookAction
$this->updateProfileBox($notice);
}
- if ($this->arg('status_submit') == 'Send') {
+ if ($this->arg('status_submit') == 'Send') {
$this->saveNewNotice();
}
@@ -81,7 +80,7 @@ class FacebookhomeAction extends FacebookAction
// Facebook status update permission? Then show the main page
// of the app
$this->showPage();
-
+
} else {
// User hasn't authenticated yet, prompt for creds
@@ -89,12 +88,12 @@ class FacebookhomeAction extends FacebookAction
}
}
-
+
function login()
{
-
+
$this->showStylesheets();
-
+
$nickname = common_canonical_nickname($this->trimmed('nickname'));
$password = $this->arg('password');
@@ -141,13 +140,12 @@ class FacebookhomeAction extends FacebookAction
$this->facebook->api_client->data_setUserPreference(
FACEBOOK_PROMPTED_UPDATE_PREF, 'false');
}
-
function showNoticeForm()
{
$post_action = "$this->app_uri/index.php";
-
- $notice_form = new FacebookNoticeForm($this, $post_action, null,
+
+ $notice_form = new FacebookNoticeForm($this, $post_action, null,
$post_action, $this->user);
$notice_form->show();
}
@@ -163,9 +161,8 @@ class FacebookhomeAction extends FacebookAction
function showContent()
{
- $notice = $this->user->noticesWithFriends(($this->page-1) *
- NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
-
+ $notice = $this->user->noticeInbox(($this->page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+
$nl = new NoticeList($notice, $this);
$cnt = $nl->show();
@@ -176,7 +173,7 @@ class FacebookhomeAction extends FacebookAction
function showNoticeList($notice)
{
-
+
$nl = new NoticeList($notice, $this);
return $nl->show();
}
@@ -201,16 +198,16 @@ class FacebookhomeAction extends FacebookAction
$this->elementStart('ul', array('id' => 'fb-permissions-list'));
$this->elementStart('li', array('id' => 'fb-permissions-item'));
-
+
$next = urlencode("$this->app_uri/index.php");
$api_key = common_config('facebook', 'apikey');
-
+
$auth_url = 'http://www.facebook.com/authorize.php?api_key=' .
- $api_key . '&v=1.0&ext_perm=status_update&next=' . $next .
+ $api_key . '&v=1.0&ext_perm=status_update&next=' . $next .
'&next_cancel=' . $next . '&submit=skip';
-
+
$this->elementStart('span', array('class' => 'facebook-button'));
- $this->element('a', array('href' => $auth_url),
+ $this->element('a', array('href' => $auth_url),
sprintf(_('Okay, do it!'), $this->app_name));
$this->elementEnd('span');
@@ -225,7 +222,7 @@ class FacebookhomeAction extends FacebookAction
$this->elementEnd('div');
}
-
+
/**
* Generate pagination links
*
@@ -239,11 +236,11 @@ class FacebookhomeAction extends FacebookAction
*/
function pagination($have_before, $have_after, $page, $action, $args=null)
{
-
+
// Does a little before-after block for next/prev page
-
+
// XXX: Fix so this uses common_local_url() if possible.
-
+
if ($have_before || $have_after) {
$this->elementStart('div', array('class' => 'pagination'));
$this->elementStart('dl', null);
@@ -254,7 +251,7 @@ class FacebookhomeAction extends FacebookAction
if ($have_before) {
$pargs = array('page' => $page-1);
$newargs = $args ? array_merge($args, $pargs) : $pargs;
- $this->elementStart('li', array('class' => 'nav_prev'));
+ $this->elementStart('li', array('class' => 'nav_prev'));
$this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'prev'),
_('After'));
$this->elementEnd('li');
@@ -274,6 +271,5 @@ class FacebookhomeAction extends FacebookAction
$this->elementEnd('div');
}
}
-
}
diff --git a/classes/Notice.php b/classes/Notice.php
index e621805df..93a1a1a4d 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -406,8 +406,10 @@ class Notice extends Memcached_DataObject
while ($user->fetch()) {
$cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id));
+ $cache->delete(common_cache_key('notice_inbox:by_user_own:'.$user->id));
if ($blowLast) {
$cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id.';last'));
+ $cache->delete(common_cache_key('notice_inbox:by_user_own:'.$user->id.';last'));
}
}
$user->free();
diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php
index 367a35f1f..4ca2e9ae3 100644
--- a/classes/Notice_inbox.php
+++ b/classes/Notice_inbox.php
@@ -47,20 +47,25 @@ class Notice_inbox extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function stream($user_id, $offset, $limit, $since_id, $max_id, $since)
+ function stream($user_id, $offset, $limit, $since_id, $max_id, $since, $own=false)
{
return Notice::stream(array('Notice_inbox', '_streamDirect'),
- array($user_id),
- 'notice_inbox:by_user:'.$user_id,
+ array($user_id, $own),
+ ($own) ? 'notice_inbox:by_user:'.$user_id :
+ 'notice_inbox:by_user_own:'.$user_id,
$offset, $limit, $since_id, $max_id, $since);
}
- function _streamDirect($user_id, $offset, $limit, $since_id, $max_id, $since)
+ function _streamDirect($user_id, $own, $offset, $limit, $since_id, $max_id, $since)
{
$inbox = new Notice_inbox();
$inbox->user_id = $user_id;
+ if (!$own) {
+ $inbox->whereAdd('source != ' . NOTICE_INBOX_SOURCE_GATEWAY);
+ }
+
if ($since_id != 0) {
$inbox->whereAdd('notice_id > ' . $since_id);
}
diff --git a/classes/User.php b/classes/User.php
index c7eede94e..e8c8c5a75 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -442,6 +442,33 @@ class User extends Memcached_DataObject
$qry =
'SELECT notice.* ' .
'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
+ 'WHERE subscription.subscriber = %d ' .
+ 'AND notice.is_local != ' . NOTICE_GATEWAY;
+ return Notice::getStream(sprintf($qry, $this->id),
+ 'user:notices_with_friends:' . $this->id,
+ $offset, $limit, $since_id, $before_id,
+ $order, $since);
+ } else if ($enabled === true ||
+ ($enabled == 'transitional' && $this->inboxed == 1)) {
+
+ $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
+
+ return Notice::getStreamByIds($ids);
+ }
+ }
+
+ function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
+ {
+ $enabled = common_config('inboxes', 'enabled');
+
+ // Complicated code, depending on whether we support inboxes yet
+ // XXX: make this go away when inboxes become mandatory
+
+ if ($enabled === false ||
+ ($enabled == 'transitional' && $this->inboxed == 0)) {
+ $qry =
+ 'SELECT notice.* ' .
+ 'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
'WHERE subscription.subscriber = %d ';
return Notice::getStream(sprintf($qry, $this->id),
'user:notices_with_friends:' . $this->id,
@@ -450,7 +477,7 @@ class User extends Memcached_DataObject
} else if ($enabled === true ||
($enabled == 'transitional' && $this->inboxed == 1)) {
- $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since);
+ $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
return Notice::getStreamByIds($ids);
}
diff --git a/scripts/twitterstatusfetcher.php b/scripts/twitterstatusfetcher.php
index 9287b6d73..d332fb555 100755
--- a/scripts/twitterstatusfetcher.php
+++ b/scripts/twitterstatusfetcher.php
@@ -1,6 +1,6 @@
#!/usr/bin/env php
<?php
-/*
+/**
* Laconica - a distributed open-source microblogging tool
* Copyright (C) 2008, Controlez-Vous, Inc.
*
@@ -35,26 +35,51 @@ define('POLL_INTERVAL', 60); // in seconds
// Uncomment this to get useful logging
define('SCRIPT_DEBUG', true);
-require_once(INSTALLDIR . '/lib/common.php');
-require_once(INSTALLDIR . '/lib/daemon.php');
+require_once INSTALLDIR . '/lib/common.php';
+require_once INSTALLDIR . '/lib/daemon.php';
+
+/**
+ * Fetcher for statuses from Twitter
+ *
+ * Fetches statuses from Twitter and inserts them as notices in local
+ * system.
+ *
+ * @category Twitter
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
class TwitterStatusFetcher extends Daemon
{
+ private $_children = array();
- private $children = array();
+ /**
+ * Name of this daemon
+ *
+ * @return string Name of the daemon.
+ */
function name()
{
return ('twitterstatusfetcher.generic');
}
+ /**
+ * Run the daemon
+ *
+ * @return void
+ */
+
function run()
{
do {
$flinks = $this->refreshFlinks();
- foreach ($flinks as $f){
+ foreach ($flinks as $f) {
// We have to disconnect from the DB before forking so
// each sub-process will open its own connection and
@@ -73,10 +98,11 @@ class TwitterStatusFetcher extends Daemon
// Parent
if (defined('SCRIPT_DEBUG')) {
- common_debug("Parent: forked new status fetcher process " . $pid);
+ common_debug("Parent: forked new status ".
+ " fetcher process " . $pid);
}
- $this->children[] = $pid;
+ $this->_children[] = $pid;
} else {
@@ -86,41 +112,41 @@ class TwitterStatusFetcher extends Daemon
}
// Remove child from ps list as it finishes
- while(($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) {
+ while (($c = pcntl_wait($status, WNOHANG OR WUNTRACED)) > 0) {
if (defined('SCRIPT_DEBUG')) {
common_debug("Child $c finished.");
}
- $this->remove_ps($this->children, $c);
+ $this->removePs($this->_children, $c);
}
// Wait! We have too many damn kids.
- if (sizeof($this->children) > MAXCHILDREN) {
+ if (sizeof($this->_children) > MAXCHILDREN) {
if (defined('SCRIPT_DEBUG')) {
common_debug('Too many children. Waiting...');
}
- if (($c = pcntl_wait($status, WUNTRACED)) > 0){
+ if (($c = pcntl_wait($status, WUNTRACED)) > 0) {
if (defined('SCRIPT_DEBUG')) {
common_debug("Finished waiting for $c");
}
- $this->remove_ps($this->children, $c);
+ $this->removePs($this->_children, $c);
}
}
}
// Remove all children from the process list before restarting
- while(($c = pcntl_wait($status, WUNTRACED)) > 0) {
+ while (($c = pcntl_wait($status, WUNTRACED)) > 0) {
if (defined('SCRIPT_DEBUG')) {
common_debug("Child $c finished.");
}
- $this->remove_ps($this->children, $c);
+ $this->removePs($this->_children, $c);
}
// Rest for a bit before we fetch more statuses
@@ -137,10 +163,18 @@ class TwitterStatusFetcher extends Daemon
} while (true);
}
- function refreshFlinks() {
+ /**
+ * Refresh the foreign links for this user
+ *
+ * @return void
+ */
+ function refreshFlinks()
+ {
$flink = new Foreign_link();
+
$flink->service = 1; // Twitter
+
$flink->orderBy('last_noticesync');
$cnt = $flink->find();
@@ -166,7 +200,18 @@ class TwitterStatusFetcher extends Daemon
return $flinks;
}
- function remove_ps(&$plist, $ps){
+ /**
+ * Unknown
+ *
+ * @param array &$plist unknown.
+ * @param string $ps unknown.
+ *
+ * @return unknown
+ * @todo document
+ */
+
+ function removePs(&$plist, $ps)
+ {
for ($i = 0; $i < sizeof($plist); $i++) {
if ($plist[$i] == $ps) {
unset($plist[$i]);
@@ -178,7 +223,6 @@ class TwitterStatusFetcher extends Daemon
function getTimeline($flink)
{
-
if (empty($flink)) {
common_log(LOG_WARNING,
"Can't retrieve Foreign_link for foreign ID $fid");
@@ -247,23 +291,32 @@ class TwitterStatusFetcher extends Daemon
return null;
}
+ // XXX: change of screen name?
+
$uri = 'http://twitter.com/' . $status->user->screen_name .
'/status/' . $status->id;
$notice = Notice::staticGet('uri', $uri);
// check to see if we've already imported the status
- if (!$notice) {
- $created = strftime('%Y-%m-%d %H:%M:%S',
- strtotime($status->created_at));;
-
- $notice = Notice::saveNew($id, $status->text, 'twitter',
- -2, null, $uri, $created);
+ if (!$notice) {
- if (defined('SCRIPT_DEBUG')) {
- common_debug("Saved status $status->id" .
- " as notice $notice->id.");
+ $notice = new Notice();
+
+ $notice->profile_id = $id;
+ $notice->uri = $uri;
+ $notice->created = strftime('%Y-%m-%d %H:%M:%S',
+ strtotime($status->created_at));
+ $notice->content = common_shorten_links($status->text); // XXX
+ $notice->rendered = common_render_content($notice->content, $notice);
+ $notice->source = 'twitter';
+ $notice->reply_to = null; // XXX lookup reply
+ $notice->is_local = NOTICE_GATEWAY;
+
+ if (Event::handle('StartNoticeSave', array(&$notice))) {
+ $id = $notice->insert();
+ Event::handle('EndNoticeSave', array($notice));
}
}
@@ -271,9 +324,11 @@ class TwitterStatusFetcher extends Daemon
'user_id' => $flink->user_id))) {
// Add to inbox
$inbox = new Notice_inbox();
- $inbox->user_id = $flink->user_id;
+
+ $inbox->user_id = $flink->user_id;
$inbox->notice_id = $notice->id;
- $inbox->created = $notice->created;
+ $inbox->created = $notice->created;
+ $inbox->source = NOTICE_INBOX_SOURCE_GATEWAY; // From a private source
$inbox->insert();
}