Can't see any posts currently - after the big shakeup, but we can now post top level activities and store them.

This commit is contained in:
friendica 2012-10-03 22:28:19 -07:00
parent d0f62d1219
commit e124c9fa5c
17 changed files with 91 additions and 138 deletions

12
README
View File

@ -1,8 +1,10 @@
Friendica RED Social Communications Server
==========================================
Friendica RED Interaction Engine
================================
http://friendica.com
Red is a new concept in electronic communications which is based on our earlier work with Friendica and our pioneering developments in decentralised, federated social networking.
Welcome to the free social web.
Red is prototype code and does not currently function. This message will be changed when it approaches stability.
Red is prototype code and does not currently function. This message will be changed when it approaches stability.
At its heart, Red is a decentralised collection of location agnostic info streams (e.g. "channels") which are attached to permission controlled web resources, and which have the ability to discover each other and interact.
Social networking emulation is one form that these streams can take, but they can take many other forms - limited only by your magination.

View File

@ -368,9 +368,11 @@ if(! class_exists('App')) {
class App {
public $account = null;
private $channel = null;
private $widgets = array();
private $channel = null;
private $observer = null;
private $widgets = array();
public $language;
public $module_loaded = false;
public $query_string;
@ -612,6 +614,15 @@ if(! class_exists('App')) {
return $this->channel;
}
function set_observer($xchan) {
$this->observer = $xchan;
}
function get_observer() {
return $this->observer;
}
function set_widget($title,$html, $location = 'aside') {
$this->widgets[] = array('title' => $title, 'html' => $html, 'location' => $location);
}

View File

@ -209,7 +209,7 @@ function event_store($arr) {
$arr['edited'] = (($arr['edited']) ? $arr['edited'] : datetime_convert());
$arr['type'] = (($arr['type']) ? $arr['type'] : 'event' );
$arr['cid'] = ((intval($arr['cid'])) ? intval($arr['cid']) : 0);
$arr['uri'] = (x($arr,'uri') ? $arr['uri'] : item_new_uri($a->get_hostname(),$arr['uid']));
$arr['uri'] = (x($arr,'uri') ? $arr['uri'] : item_message_id());
$arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0);
if($arr['cid'])

View File

@ -931,6 +931,7 @@ function item_store($arr,$force_parent = false) {
return 0;
}
if(x($arr, 'gravity'))
$arr['gravity'] = intval($arr['gravity']);
elseif($arr['parent_uri'] === $arr['uri'])
@ -964,14 +965,11 @@ function item_store($arr,$force_parent = false) {
$arr['body'] = strip_tags($arr['body']);
$arr['aid'] = ((x($arr,'aid')) ? intval($arr['aid']) : 0);
$arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
$arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string());
$arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : '');
$arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : '');
$arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : '');
$arr['owner-name'] = ((x($arr,'owner-name')) ? notags(trim($arr['owner-name'])) : '');
$arr['owner-link'] = ((x($arr,'owner-link')) ? notags(trim($arr['owner-link'])) : '');
$arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : '');
$arr['author_xchan'] = ((x($arr,'author_xchan')) ? notags(trim($arr['author_xchan'])) : '');
$arr['owner_xchan'] = ((x($arr,'owner_xchan')) ? notags(trim($arr['owner_xchan'])) : '');
$arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
$arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
$arr['commented'] = datetime_convert();

View File

@ -25,32 +25,13 @@ function authenticate_success($user_record, $login_initial = false, $interactive
}
$uid_to_load = (((x($_SESSION,'uid')) && (intval($_SESSION['uid']))) ? intval($_SESSION['uid']) : 0);
if(! $uid_to_load)
$uid_to_load = intval($a->account['account_default_channel']);
$uid_to_load = (((x($_SESSION,'uid')) && (intval($_SESSION['uid'])))
? intval($_SESSION['uid'])
: intval($a->account['account_default_channel'])
);
if($uid_to_load) {
$r = q("select * from channel where channel_id = %d and channel_account_id = %d limit 1",
intval($uid_to_load),
intval($a->account['account_id'])
);
if($r && count($r)) {
$_SESSION['uid'] = intval($r[0]['channel_id']);
$a->set_channel($r[0]);
$_SESSION['theme'] = $r[0]['channel_theme'];
date_default_timezone_set($r[0]['channel_timezone']);
}
$c = q("SELECT * FROM contact WHERE uid = %d AND self = 1 LIMIT 1",
intval($r[0]['channel_id'])
);
if($c && count($c)) {
$a->contact = $c[0];
$a->cid = $c[0]['id'];
$_SESSION['cid'] = $a->cid;
}
change_channel($uid_to_load);
}
}
@ -222,7 +203,7 @@ function can_write_wall(&$a,$owner) {
function change_channel($change_channel) {
$r = false;
$ret = false;
if($change_channel) {
$r = q("select * from channel where channel_id = %d and channel_account_id = %d limit 1",
@ -230,14 +211,21 @@ function change_channel($change_channel) {
intval(get_account_id())
);
if($r && count($r)) {
$hash = $r[0]['channel_hash'];
$_SESSION['uid'] = intval($r[0]['channel_id']);
get_app()->set_channel($r[0]);
$_SESSION['theme'] = $r[0]['channel_theme'];
date_default_timezone_set($r[0]['channel_timezone']);
$ret = $r[0];
}
$x = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($hash)
);
if($x && count($x))
get_app()->set_observer($x[0]);
}
return $r;
return $ret;
}

View File

@ -352,14 +352,14 @@ function perms2str($p) {
// generate a guaranteed unique (for this domain) item ID for ATOM
// safe from birthday paradox
if(! function_exists('item_new_uri')) {
function item_new_uri($hostname,$uid) {
if(! function_exists('item_message_id')) {
function item_message_id() {
do {
$dups = false;
$hash = random_string();
$uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash;
$uri = $hash . '@' . $hostname;
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($uri));

View File

@ -439,7 +439,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
if(count($self)) {
$arr = array();
$arr['uri'] = $arr['parent_uri'] = item_new_uri($a->get_hostname(), $uid);
$arr['uri'] = $arr['parent_uri'] = item_message_id();
$arr['uid'] = $uid;
$arr['contact-id'] = $self[0]['id'];
$arr['wall'] = 1;
@ -760,7 +760,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
if(count($self)) {
$arr = array();
$arr['uri'] = $arr['parent_uri'] = item_new_uri($a->get_hostname(), $local_uid);
$arr['uri'] = $arr['parent_uri'] = item_message_id();
$arr['uid'] = $local_uid;
$arr['contact-id'] = $self[0]['id'];
$arr['wall'] = 1;

View File

@ -18,6 +18,7 @@
require_once('include/crypto.php');
require_once('include/enotify.php');
require_once('include/email.php');
require_once('include/items.php');
function item_post(&$a) {
@ -173,14 +174,28 @@ function item_post(&$a) {
$orig_post = $i[0];
}
$user = null;
$channel = null;
if(local_user() && local_user() == $profile_uid) {
$channel = $a->get_channel();
$observer = $a->get_observer();
}
else {
$r = q("SELECT channel.*, account.* FROM channel left join account on channel.channel_account_id = account.account_id
where channel.channel_id = %d LIMIT 1",
intval($profile_uid)
);
if(count($r))
$channel = $r[0];
}
if(! $channel) {
logger("mod_item: no channel.");
if(x($_REQUEST,'return'))
goaway($a->get_baseurl() . "/" . $return_path );
killme();
}
$r = q("SELECT channel.*, account.* FROM channel left join account on channel.channel_account_id = account.account_id
where channel.channel_id = %d LIMIT 1",
intval($profile_uid)
);
if(count($r))
$channel = $r[0];
if($orig_post) {
$str_group_allow = $orig_post['allow_gid'];
@ -538,7 +553,8 @@ function item_post(&$a) {
$notify_type = (($parent) ? 'comment-new' : 'wall-new' );
$uri = item_new_uri($a->get_hostname(),$profile_uid);
$uri = item_message_id();
// Fallback so that we alway have a thr_parent
@ -546,17 +562,19 @@ function item_post(&$a) {
$thr_parent = $uri;
$datarray = array();
if(! $parent)
$datarray['parent_uri'] = $uri;
$datarray['aid'] = get_account_id(); // fixme
$datarray['uid'] = $profile_uid;
$datarray['type'] = $post_type;
$datarray['wall'] = $wall;
$datarray['gravity'] = $gravity;
$datarray['contact-id'] = $contact_id;
$datarray['owner-name'] = $contact_record['name'];
$datarray['owner-link'] = $contact_record['url'];
$datarray['owner-avatar'] = $contact_record['thumb'];
$datarray['author-name'] = $author['name'];
$datarray['author-link'] = $author['url'];
$datarray['author-avatar'] = $author['thumb'];
$datarray['owner_xchan'] = $observer['xchan_hash']; // fixme
$datarray['author_xchan'] = $observer['xchan_hash'];
$datarray['created'] = datetime_convert();
$datarray['edited'] = datetime_convert();
$datarray['commented'] = datetime_convert();
@ -582,18 +600,6 @@ function item_post(&$a) {
$datarray['origin'] = $origin;
$datarray['moderated'] = $allow_moderated;
/**
* These fields are for the convenience of plugins...
* 'self' if true indicates the owner is posting on their own wall
* If parent is 0 it is a top-level post.
*/
$datarray['parent'] = $parent;
$datarray['self'] = $self;
if($orig_post)
$datarray['edit'] = true;
// preview mode - prepare the body for display and send it via json
@ -671,54 +677,11 @@ function item_post(&$a) {
$post_id = 0;
$r = q("INSERT INTO `item` (`uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
`author-name`, `author-link`, `author-avatar`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr_parent`, `title`, `body`, `app`, `lang`, `location`, `coord`,
`inform`, `verb`, `postopts`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `attach`,`origin`, `moderated`)
VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d )",
intval($datarray['uid']),
dbesc($datarray['type']),
intval($datarray['wall']),
intval($datarray['gravity']),
intval($datarray['contact-id']),
dbesc($datarray['owner-name']),
dbesc($datarray['owner-link']),
dbesc($datarray['owner-avatar']),
dbesc($datarray['author-name']),
dbesc($datarray['author-link']),
dbesc($datarray['author-avatar']),
dbesc($datarray['created']),
dbesc($datarray['edited']),
dbesc($datarray['commented']),
dbesc($datarray['received']),
dbesc($datarray['changed']),
dbesc($datarray['uri']),
dbesc($datarray['thr_parent']),
dbesc($datarray['title']),
dbesc($datarray['body']),
dbesc($datarray['app']),
dbesc($datarray['lang']),
dbesc($datarray['location']),
dbesc($datarray['coord']),
dbesc($datarray['inform']),
dbesc($datarray['verb']),
dbesc($datarray['postopts']),
dbesc($datarray['allow_cid']),
dbesc($datarray['allow_gid']),
dbesc($datarray['deny_cid']),
dbesc($datarray['deny_gid']),
intval($datarray['private']),
dbesc($datarray['attach']),
intval($datarray['origin']),
intval($datarray['moderated'])
);
$post_id = item_store($datarray);
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($datarray['uri']));
if(count($r)) {
$post_id = $r[0]['id'];
if($post_id) {
logger('mod_item: saved item ' . $post_id);
if(count($post_tags)) {
foreach($post_tags as $tag) {
if(strlen(trim($tag['term']))) {
@ -841,15 +804,6 @@ function item_post(&$a) {
call_hooks('post_local_end', $datarray);
// This is a real juggling act on shared hosting services which kill your processes
// e.g. dreamhost. We used to start delivery to our native delivery agents in the background
// and then run our plugin delivery from the foreground. We're now doing plugin delivery first,
// because as soon as you start loading up a bunch of remote delivey processes, *this* page is
// likely to get killed off. If you end up looking at an /item URL and a blank page,
// it's very likely the delivery got killed before all your friends could be notified.
// Currently the only realistic fixes are to use a reliable server - which precludes shared hosting,
// or cut back on plugins which do remote deliveries.
proc_run('php', "include/notifier.php", $notify_type, "$post_id");
logger('post_complete');

View File

@ -127,7 +127,7 @@ function like_content(&$a) {
return;
}
$uri = item_new_uri($a->get_hostname(),$owner_uid);
$uri = item_message_id();
$post_type = (($item['resource_id']) ? t('photo') : t('status'));
$objtype = (($item['resource_id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );

View File

@ -14,8 +14,8 @@ function manage_content(&$a) {
if($change_channel) {
$r = change_channel($change_channel);
if($r && $r[0]['channel_startpage'])
goaway(z_root() . '/' . $r[0]['channel_startpage']);
if($r && $r['channel_startpage'])
goaway(z_root() . '/' . $r['channel_startpage']);
goaway(z_root());
}

View File

@ -57,7 +57,7 @@ function mood_init(&$a) {
$poster = $a->contact;
$uri = item_new_uri($a->get_hostname(),$uid);
$uri = item_message_id();
$action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' , $verbs[$verb]);

View File

@ -405,7 +405,7 @@ function photos_post(&$a) {
// Create item container
$title = '';
$uri = item_new_uri($a->get_hostname(),$page_owner_uid);
$uri = item_message_id();
$arr = array();
@ -588,7 +588,7 @@ function photos_post(&$a) {
if(count($taginfo)) {
foreach($taginfo as $tagged) {
$uri = item_new_uri($a->get_hostname(),$page_owner_uid);
$uri = item_message_id();
$arr = array();
@ -805,7 +805,7 @@ function photos_post(&$a) {
}
$basename = basename($filename);
$uri = item_new_uri($a->get_hostname(), $page_owner_uid);
$uri = item_message_id();
// Create item container

View File

@ -76,7 +76,7 @@ function poke_init(&$a) {
$poster = $a->contact;
$uri = item_new_uri($a->get_hostname(),$uid);
$uri = item_message_id();
$arr = array();

View File

@ -338,7 +338,7 @@ function profile_activity($changed, $value) {
return;
$arr = array();
$arr['uri'] = $arr['parent_uri'] = item_new_uri($a->get_hostname(), local_user());
$arr['uri'] = $arr['parent_uri'] = item_message_id();
$arr['uid'] = local_user();
$arr['contact-id'] = $self[0]['id'];
$arr['wall'] = 1;

View File

@ -82,7 +82,7 @@ function subthread_content(&$a) {
return;
}
$uri = item_new_uri($a->get_hostname(),$owner_uid);
$uri = item_message_id();
$post_type = (($item['resource_id']) ? t('photo') : t('status'));
$objtype = (($item['resource_id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );

View File

@ -57,7 +57,7 @@ function tagger_content(&$a) {
return;
}
$uri = item_new_uri($a->get_hostname(),$owner_uid);
$uri = item_message_id();
$xterm = xmlify($term);
$post_type = (($item['resource_id']) ? t('photo') : t('status'));
$targettype = (($item['resource_id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );

View File

@ -1 +1 @@
2012-10-01.94
2012-10-03.96