1
1
Fork 0

Merge pull request #2418 from annando/1602-diaspora

New Diaspora implementation
This commit is contained in:
Tobias Diekershoff 2016-03-30 11:06:38 +02:00
commit 1b64aadfcd
41 changed files with 3312 additions and 3736 deletions

View file

@ -201,17 +201,6 @@ CREATE TABLE IF NOT EXISTS `deliverq` (
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE dsprphotoq
--
CREATE TABLE IF NOT EXISTS `dsprphotoq` (
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`msg` mediumtext NOT NULL,
`attempt` tinyint(4) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE event
--
@ -912,13 +901,11 @@ CREATE TABLE IF NOT EXISTS `session` (
CREATE TABLE IF NOT EXISTS `sign` (
`id` int(10) unsigned NOT NULL auto_increment,
`iid` int(10) unsigned NOT NULL DEFAULT 0,
`retract_iid` int(10) unsigned NOT NULL DEFAULT 0,
`signed_text` mediumtext NOT NULL,
`signature` text NOT NULL,
`signer` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
INDEX `iid` (`iid`),
INDEX `retract_iid` (`retract_iid`)
INDEX `iid` (`iid`)
) DEFAULT CHARSET=utf8;
--

View file

@ -15,7 +15,6 @@ Database Tables
| [contact](help/database/db_contact) | contact table |
| [conv](help/database/db_conv) | private messages |
| [deliverq](help/database/db_deliverq) | |
| [dsprphotoq](help/database/db_dsprphotoq) | |
| [event](help/database/db_event) | Events |
| [fcontact](help/database/db_fcontact) | friend suggestion stuff |
| [ffinder](help/database/db_ffinder) | friend suggestion stuff |

View file

@ -1,11 +0,0 @@
Table dsprphotoq
================
| Field | Description | Type | Null | Key | Default | Extra |
|---------|------------------|------------------|------|-----|---------|----------------|
| id | sequential ID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| uid | | int(11) | NO | | 0 | |
| msg | | mediumtext | NO | | NULL | |
| attempt | | tinyint(4) | NO | | 0 | |
Return to [database documentation](help/database)

View file

@ -5,7 +5,6 @@ Table sign
| ------------ | ------------- | ---------------- | ---- | --- | ------- | --------------- |
| id | sequential ID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| iid | item.id | int(10) unsigned | NO | MUL | 0 | |
| retract_iid | | int(10) unsigned | NO | MUL | 0 | |
| signed_text | | mediumtext | NO | | NULL | |
| signature | | text | NO | | NULL | |
| signer | | varchar(255) | NO | | | |

View file

@ -129,7 +129,7 @@ function terminate_friendship($user,$self,$contact) {
}
elseif($contact['network'] === NETWORK_DIASPORA) {
require_once('include/diaspora.php');
diaspora_unshare($user,$contact);
diaspora::send_unshare($user,$contact);
}
elseif($contact['network'] === NETWORK_DFRN) {
require_once('include/dfrn.php');

View file

@ -99,7 +99,7 @@ function network_to_name($s, $profile = "") {
$networkname = str_replace($search,$replace,$s);
if (($s == NETWORK_DIASPORA) AND ($profile != "") AND diaspora_is_redmatrix($profile)) {
if (($s == NETWORK_DIASPORA) AND ($profile != "") AND diaspora::is_redmatrix($profile)) {
$networkname = t("Hubzilla/Redmatrix");
$r = q("SELECT `gserver`.`platform` FROM `gcontact`

View file

@ -71,10 +71,6 @@ function cron_run(&$argv, &$argc){
proc_run('php',"include/queue.php");
// run diaspora photo queue process in the background
proc_run('php',"include/dsprphotoq.php");
// run the process to discover global contacts in the background
proc_run('php',"include/discover_poco.php");

View file

@ -537,17 +537,6 @@ function db_definition() {
"PRIMARY" => array("id"),
)
);
$database["dsprphotoq"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"msg" => array("type" => "mediumtext", "not null" => "1"),
"attempt" => array("type" => "tinyint(4)", "not null" => "1", "default" => "0"),
),
"indexes" => array(
"PRIMARY" => array("id"),
)
);
$database["event"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
@ -1246,7 +1235,6 @@ function db_definition() {
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"retract_iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"signed_text" => array("type" => "mediumtext", "not null" => "1"),
"signature" => array("type" => "text", "not null" => "1"),
"signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1254,7 +1242,6 @@ function db_definition() {
"indexes" => array(
"PRIMARY" => array("id"),
"iid" => array("iid"),
"retract_iid" => array("retract_iid"),
)
);
$database["spam"] = array(

View file

@ -68,7 +68,7 @@ function delivery_run(&$argv, &$argc){
dbesc($contact_id)
);
if((! $item_id) || (! $contact_id))
if (!$item_id || !$contact_id)
continue;
$expire = false;
@ -230,7 +230,7 @@ function delivery_run(&$argv, &$argc){
$relay_to_owner = false;
if((! $top_level) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) {
if (!$top_level && ($parent['wall'] == 0) && !$expire && stristr($target_item['uri'],$localhost)) {
$relay_to_owner = true;
}
@ -243,7 +243,8 @@ function delivery_run(&$argv, &$argc){
if ((strlen($parent['allow_cid']))
|| (strlen($parent['allow_gid']))
|| (strlen($parent['deny_cid']))
|| (strlen($parent['deny_gid']))) {
|| (strlen($parent['deny_gid']))
|| $parent["private"]) {
$public_message = false; // private recipients, not public
}
@ -294,7 +295,7 @@ function delivery_run(&$argv, &$argc){
continue;
// private emails may be in included in public conversations. Filter them.
if(($public_message) && $item['private'])
if ($public_message && $item['private'])
continue;
$item_contact = get_item_contact($item,$icontacts);
@ -349,8 +350,8 @@ function delivery_run(&$argv, &$argc){
if ($x && count($x)) {
$write_flag = ((($x[0]['rel']) && ($x[0]['rel'] != CONTACT_IS_SHARING)) ? true : false);
if((($owner['page-flags'] == PAGE_COMMUNITY) || ($write_flag)) && (! $x[0]['writable'])) {
q("update contact set writable = 1 where id = %d",
if ((($owner['page-flags'] == PAGE_COMMUNITY) || $write_flag) && !$x[0]['writable']) {
q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d",
intval($x[0]['id'])
);
$x[0]['writable'] = 1;
@ -439,7 +440,7 @@ function delivery_run(&$argv, &$argc){
// only expose our real email address to true friends
if(($contact['rel'] == CONTACT_IS_FRIEND) && (! $contact['blocked'])) {
if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) {
if ($reply_to) {
$headers = 'From: '.email_header_encode($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n";
$headers .= 'Sender: '.$local_user[0]['email']."\n";
@ -500,14 +501,14 @@ function delivery_run(&$argv, &$argc){
break;
if ($mail) {
diaspora_send_mail($item,$owner,$contact);
diaspora::send_mail($item,$owner,$contact);
break;
}
if (!$normal_mode)
break;
if((! $contact['pubkey']) && (! $public_message))
if (!$contact['pubkey'] && !$public_message)
break;
$unsupported_activities = array(ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
@ -521,24 +522,23 @@ function delivery_run(&$argv, &$argc){
if (($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) {
// top-level retraction
logger('delivery: diaspora retract: ' . $loc);
diaspora_send_retraction($target_item,$owner,$contact,$public_message);
logger('diaspora retract: '.$loc);
diaspora::send_retraction($target_item,$owner,$contact,$public_message);
break;
} elseif ($followup) {
// send comments and likes to owner to relay
diaspora_send_followup($target_item,$owner,$contact,$public_message);
logger('diaspora followup: '.$loc);
diaspora::send_followup($target_item,$owner,$contact,$public_message);
break;
} elseif ($target_item['uri'] !== $target_item['parent-uri']) {
// we are the relay - send comments, likes and relayable_retractions to our conversants
logger('delivery: diaspora relay: ' . $loc);
diaspora_send_relay($target_item,$owner,$contact,$public_message);
logger('diaspora relay: '.$loc);
diaspora::send_relay($target_item,$owner,$contact,$public_message);
break;
} elseif(($top_level) && (! $walltowall)) {
} elseif ($top_level && !$walltowall) {
// currently no workable solution for sending walltowall
logger('delivery: diaspora status: ' . $loc);
diaspora_send_status($target_item,$owner,$contact,$public_message);
logger('diaspora status: '.$loc);
diaspora::send_status($target_item,$owner,$contact,$public_message);
break;
}

File diff suppressed because it is too large Load diff

View file

@ -1,55 +0,0 @@
<?php
require_once("boot.php");
require_once('include/diaspora.php');
function dsprphotoq_run($argv, $argc){
global $a, $db;
if(is_null($a)){
$a = new App;
}
if(is_null($db)){
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
logger("diaspora photo queue: running", LOGGER_DEBUG);
$r = q("SELECT * FROM dsprphotoq");
if(!$r)
return;
$dphotos = $r;
logger("diaspora photo queue: processing " . count($dphotos) . " photos");
foreach($dphotos as $dphoto) {
$r = array();
if ($dphoto['uid'] == 0)
$r[0] = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
else
$r = q("SELECT * FROM user WHERE uid = %d",
intval($dphoto['uid']));
if(!$r) {
logger("diaspora photo queue: user " . $dphoto['uid'] . " not found");
return;
}
$ret = diaspora_dispatch($r[0],unserialize($dphoto['msg']),$dphoto['attempt']);
q("DELETE FROM dsprphotoq WHERE id = %d",
intval($dphoto['id'])
);
}
}
if (array_search(__file__,get_included_files())===0){
dsprphotoq_run($_SERVER["argv"],$_SERVER["argc"]);
killme();
}

View file

@ -303,8 +303,8 @@ function new_contact($uid,$url,$interactive = false) {
}
if($contact['network'] == NETWORK_DIASPORA) {
require_once('include/diaspora.php');
$ret = diaspora_share($a->user,$contact);
logger('mod_follow: diaspora_share returns: ' . $ret);
$ret = diaspora::send_share($a->user,$contact);
logger('share returns: '.$ret);
}
}

View file

@ -1980,9 +1980,6 @@ function drop_item($id,$interactive = true) {
intval($r[0]['id'])
);
}
// Add a relayable_retraction signature for Diaspora.
store_diaspora_retract_sig($item, $a->user, $a->get_baseurl());
}
$drop_id = intval($item['id']);
@ -2115,51 +2112,3 @@ function posted_date_widget($url,$uid,$wall) {
));
return $o;
}
function store_diaspora_retract_sig($item, $user, $baseurl) {
// Note that we can't add a target_author_signature
// if the comment was deleted by a remote user. That should be ok, because if a remote user is deleting
// the comment, that means we're the home of the post, and Diaspora will only
// check the parent_author_signature of retractions that it doesn't have to relay further
//
// I don't think this function gets called for an "unlike," but I'll check anyway
$enabled = intval(get_config('system','diaspora_enabled'));
if(! $enabled) {
logger('drop_item: diaspora support disabled, not storing retraction signature', LOGGER_DEBUG);
return;
}
logger('drop_item: storing diaspora retraction signature');
$signed_text = $item['guid'] . ';' . ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment');
if(local_user() == $item['uid']) {
$handle = $user['nickname'] . '@' . substr($baseurl, strpos($baseurl,'://') + 3);
$authorsig = base64_encode(rsa_sign($signed_text,$user['prvkey'],'sha256'));
}
else {
$r = q("SELECT `nick`, `url` FROM `contact` WHERE `id` = '%d' LIMIT 1",
$item['contact-id'] // If this function gets called, drop_item() has already checked remote_user() == $item['contact-id']
);
if(count($r)) {
// The below handle only works for NETWORK_DFRN. I think that's ok, because this function
// only handles DFRN deletes
$handle_baseurl_start = strpos($r['url'],'://') + 3;
$handle_baseurl_length = strpos($r['url'],'/profile') - $handle_baseurl_start;
$handle = $r['nick'] . '@' . substr($r['url'], $handle_baseurl_start, $handle_baseurl_length);
$authorsig = '';
}
}
if(isset($handle))
q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
intval($item['id']),
dbesc($signed_text),
dbesc($authorsig),
dbesc($handle)
);
return;
}

View file

@ -1,4 +1,5 @@
<?php
require_once("include/diaspora.php");
/**
* @brief add/remove activity to an item
@ -151,9 +152,6 @@ function do_like($item_id, $verb) {
intval($like_item['id'])
);
// Save the author information for the unlike in case we need to relay to Diaspora
store_diaspora_like_retract_sig($activity, $item, $like_item, $contact);
$like_item_id = $like_item['id'];
proc_run('php',"include/notifier.php","like","$like_item_id");
@ -241,7 +239,7 @@ EOT;
// Save the author information for the like in case we need to relay to Diaspora
store_diaspora_like_sig($activity, $post_type, $contact, $post_id);
diaspora::store_like_signature($contact, $post_id);
$arr['id'] = $post_id;
@ -251,149 +249,3 @@ EOT;
return true;
}
function store_diaspora_like_retract_sig($activity, $item, $like_item, $contact) {
// Note that we can only create a signature for a user of the local server. We don't have
// a key for remote users. That is ok, because if a remote user is "unlike"ing a post, it
// means we are the relay, and for relayable_retractions, Diaspora
// only checks the parent_author_signature if it doesn't have to relay further
//
// If $item['resource-id'] exists, it means the item is a photo. Diaspora doesn't support
// likes on photos, so don't bother.
$enabled = intval(get_config('system','diaspora_enabled'));
if(! $enabled) {
logger('mod_like: diaspora support disabled, not storing like retraction signature', LOGGER_DEBUG);
return;
}
logger('mod_like: storing diaspora like retraction signature');
if(($activity === ACTIVITY_LIKE) && (! $item['resource-id'])) {
$signed_text = $like_item['guid'] . ';' . 'Like';
// Only works for NETWORK_DFRN
$contact_baseurl_start = strpos($contact['url'],'://') + 3;
$contact_baseurl_length = strpos($contact['url'],'/profile') - $contact_baseurl_start;
$contact_baseurl = substr($contact['url'], $contact_baseurl_start, $contact_baseurl_length);
$diaspora_handle = $contact['nick'] . '@' . $contact_baseurl;
// This code could never had worked (the return values form the queries were used in a wrong way.
// Additionally it is needlessly complicated. Either the contact is owner or not. And we have this data already.
/*
// Get contact's private key if he's a user of the local Friendica server
$r = q("SELECT `contact`.`uid` FROM `contact` WHERE `url` = '%s' AND `self` = 1 LIMIT 1",
dbesc($contact['url'])
);
if( $r) {
$contact_uid = $r['uid'];
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
intval($contact_uid)
);
*/
// Is the contact the owner? Then fetch the private key
if ($contact['self'] AND ($contact['uid'] > 0)) {
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
intval($contact['uid'])
);
if($r)
$authorsig = base64_encode(rsa_sign($signed_text,$r[0]['prvkey'],'sha256'));
}
if(! isset($authorsig))
$authorsig = '';
q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
intval($like_item['id']),
dbesc($signed_text),
dbesc($authorsig),
dbesc($diaspora_handle)
);
}
return;
}
function store_diaspora_like_sig($activity, $post_type, $contact, $post_id) {
// Note that we can only create a signature for a user of the local server. We don't have
// a key for remote users. That is ok, because if a remote user is "unlike"ing a post, it
// means we are the relay, and for relayable_retractions, Diaspora
// only checks the parent_author_signature if it doesn't have to relay further
$enabled = intval(get_config('system','diaspora_enabled'));
if(! $enabled) {
logger('mod_like: diaspora support disabled, not storing like signature', LOGGER_DEBUG);
return;
}
logger('mod_like: storing diaspora like signature');
if(($activity === ACTIVITY_LIKE) && ($post_type === t('status'))) {
// Only works for NETWORK_DFRN
$contact_baseurl_start = strpos($contact['url'],'://') + 3;
$contact_baseurl_length = strpos($contact['url'],'/profile') - $contact_baseurl_start;
$contact_baseurl = substr($contact['url'], $contact_baseurl_start, $contact_baseurl_length);
$diaspora_handle = $contact['nick'] . '@' . $contact_baseurl;
// This code could never had worked (the return values form the queries were used in a wrong way.
// Additionally it is needlessly complicated. Either the contact is owner or not. And we have this data already.
/*
// Get contact's private key if he's a user of the local Friendica server
$r = q("SELECT `contact`.`uid` FROM `contact` WHERE `url` = '%s' AND `self` = 1 LIMIT 1",
dbesc($contact['url'])
);
if( $r) {
$contact_uid = $r['uid'];
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
intval($contact_uid)
);
if( $r)
$contact_uprvkey = $r['prvkey'];
}
*/
// Is the contact the owner? Then fetch the private key
if ($contact['self'] AND ($contact['uid'] > 0)) {
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
intval($contact['uid'])
);
if($r)
$contact_uprvkey = $r[0]['prvkey'];
}
$r = q("SELECT guid, parent FROM `item` WHERE id = %d LIMIT 1",
intval($post_id)
);
if( $r) {
$p = q("SELECT guid FROM `item` WHERE id = %d AND parent = %d LIMIT 1",
intval($r[0]['parent']),
intval($r[0]['parent'])
);
if( $p) {
$signed_text = 'true;'.$r[0]['guid'].';Post;'.$p[0]['guid'].';'.$diaspora_handle;
if(isset($contact_uprvkey))
$authorsig = base64_encode(rsa_sign($signed_text,$contact_uprvkey,'sha256'));
else
$authorsig = '';
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
intval($post_id),
dbesc($signed_text),
dbesc($authorsig),
dbesc($diaspora_handle)
);
}
}
}
return;
}

View file

@ -862,64 +862,6 @@ function parse_xml_string($s,$strict = true) {
return $x;
}}
function add_fcontact($arr,$update = false) {
if($update) {
$r = q("UPDATE `fcontact` SET
`name` = '%s',
`photo` = '%s',
`request` = '%s',
`nick` = '%s',
`addr` = '%s',
`batch` = '%s',
`notify` = '%s',
`poll` = '%s',
`confirm` = '%s',
`alias` = '%s',
`pubkey` = '%s',
`updated` = '%s'
WHERE `url` = '%s' AND `network` = '%s'",
dbesc($arr['name']),
dbesc($arr['photo']),
dbesc($arr['request']),
dbesc($arr['nick']),
dbesc($arr['addr']),
dbesc($arr['batch']),
dbesc($arr['notify']),
dbesc($arr['poll']),
dbesc($arr['confirm']),
dbesc($arr['alias']),
dbesc($arr['pubkey']),
dbesc(datetime_convert()),
dbesc($arr['url']),
dbesc($arr['network'])
);
}
else {
$r = q("insert into fcontact ( `url`,`name`,`photo`,`request`,`nick`,`addr`,
`batch`, `notify`,`poll`,`confirm`,`network`,`alias`,`pubkey`,`updated` )
values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
dbesc($arr['url']),
dbesc($arr['name']),
dbesc($arr['photo']),
dbesc($arr['request']),
dbesc($arr['nick']),
dbesc($arr['addr']),
dbesc($arr['batch']),
dbesc($arr['notify']),
dbesc($arr['poll']),
dbesc($arr['confirm']),
dbesc($arr['network']),
dbesc($arr['alias']),
dbesc($arr['pubkey']),
dbesc(datetime_convert())
);
}
return $r;
}
function scale_external_images($srctext, $include_link = true, $scale_replace = false) {
// Suppress "view full size"

View file

@ -536,7 +536,7 @@ function notifier_run(&$argv, &$argc){
if($public_message) {
if (!$followup AND $top_level)
$r0 = diaspora_fetch_relay();
$r0 = diaspora::relay_list();
else
$r0 = array();
@ -628,13 +628,6 @@ function notifier_run(&$argv, &$argc){
proc_run('php','include/pubsubpublish.php');
}
// If the item was deleted, clean up the `sign` table
if($target_item['deleted']) {
$r = q("DELETE FROM sign where `retract_iid` = %d",
intval($target_item['id'])
);
}
logger('notifier: calling hooks', LOGGER_DEBUG);
if($normal_mode)

View file

@ -1,96 +1,6 @@
<?php
require_once('include/datetime.php');
require_once('include/diaspora.php');
require_once('include/queue_fn.php');
require_once('include/Contact.php');
function profile_change() {
$a = get_app();
if(! local_user())
return;
// $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
// if($url && strlen(get_config('system','directory')))
// proc_run('php',"include/directory.php","$url");
$recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'
AND `uid` = %d AND `rel` != %d ",
dbesc(NETWORK_DIASPORA),
intval(local_user()),
intval(CONTACT_IS_SHARING)
);
if(! count($recips))
return;
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
WHERE `user`.`uid` = %d AND `profile`.`is-default` = 1 LIMIT 1",
intval(local_user())
);
if(! count($r))
return;
$profile = $r[0];
$handle = xmlify($a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3));
$first = xmlify(((strpos($profile['name'],' '))
? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']));
$last = xmlify((($first === $profile['name']) ? '' : trim(substr($profile['name'],strlen($first)))));
$large = xmlify($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg');
$medium = xmlify($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg');
$small = xmlify($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg');
$searchable = xmlify((($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ));
// $searchable = 'true';
if($searchable === 'true') {
$dob = '1000-00-00';
if(($profile['dob']) && ($profile['dob'] != '0000-00-00'))
$dob = ((intval($profile['dob'])) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC','UTC',$profile['dob'],'m-d');
$gender = xmlify($profile['gender']);
$about = xmlify($profile['about']);
require_once('include/bbcode.php');
$about = xmlify(strip_tags(bbcode($about)));
$location = formatted_location($profile);
$location = xmlify($location);
$tags = '';
if($profile['pub_keywords']) {
$kw = str_replace(',',' ',$profile['pub_keywords']);
$kw = str_replace(' ',' ',$kw);
$arr = explode(' ',$profile['pub_keywords']);
if(count($arr)) {
for($x = 0; $x < 5; $x ++) {
if(trim($arr[$x]))
$tags .= '#' . trim($arr[$x]) . ' ';
}
}
}
$tags = xmlify(trim($tags));
}
$tpl = get_markup_template('diaspora_profile.tpl');
$msg = replace_macros($tpl,array(
'$handle' => $handle,
'$first' => $first,
'$last' => $last,
'$large' => $large,
'$medium' => $medium,
'$small' => $small,
'$dob' => $dob,
'$gender' => $gender,
'$about' => $about,
'$location' => $location,
'$searchable' => $searchable,
'$tags' => $tags
));
logger('profile_change: ' . $msg, LOGGER_ALL);
foreach($recips as $recip) {
$msgtosend = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$a->user,$recip,$a->user['prvkey'],$recip['pubkey'],false)));
add_to_queue($recip['id'],NETWORK_DIASPORA,$msgtosend,false);
}
diaspora::send_profile(local_user());
}

View file

@ -193,7 +193,7 @@ function queue_run(&$argv, &$argc){
case NETWORK_DIASPORA:
if($contact['notify']) {
logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = diaspora_transmit($owner,$contact,$data,$public,true);
$deliver_status = diaspora::transmit($owner,$contact,$data,$public,true);
if($deliver_status == (-1)) {
update_queue_time($q_item['id']);

96
include/xml.php Normal file
View file

@ -0,0 +1,96 @@
<?php
/**
* @file include/xml.php
*/
/**
* @brief This class contain functions to work with XML data
*
*/
class xml {
/**
* @brief Creates an XML structure out of a given array
*
* @param array $array The array of the XML structure that will be generated
* @param object $xml The createdXML will be returned by reference
* @param bool $remove_header Should the XML header be removed or not?
* @param array $namespaces List of namespaces
* @param bool $root - interally used parameter. Mustn't be used from outside.
*
* @return string The created XML
*/
public static function from_array($array, &$xml, $remove_header = false, $namespaces = array(), $root = true) {
if ($root) {
foreach($array as $key => $value) {
foreach ($namespaces AS $nskey => $nsvalue)
$key .= " xmlns".($nskey == "" ? "":":").$nskey.'="'.$nsvalue.'"';
$root = new SimpleXMLElement("<".$key."/>");
self::from_array($value, $root, $remove_header, $namespaces, false);
$dom = dom_import_simplexml($root)->ownerDocument;
$dom->formatOutput = true;
$xml = $dom;
$xml_text = $dom->saveXML();
if ($remove_header)
$xml_text = trim(substr($xml_text, 21));
return $xml_text;
}
}
foreach($array as $key => $value) {
if ($key == "@attributes") {
if (!isset($element) OR !is_array($value))
continue;
foreach ($value as $attr_key => $attr_value) {
$element_parts = explode(":", $attr_key);
if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
$namespace = $namespaces[$element_parts[0]];
else
$namespace = NULL;
$element->addAttribute ($attr_key, $attr_value, $namespace);
}
continue;
}
$element_parts = explode(":", $key);
if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
$namespace = $namespaces[$element_parts[0]];
else
$namespace = NULL;
if (!is_array($value))
$element = $xml->addChild($key, xmlify($value), $namespace);
elseif (is_array($value)) {
$element = $xml->addChild($key, NULL, $namespace);
self::from_array($value, $element, $remove_header, $namespaces, false);
}
}
}
/**
* @brief Copies an XML object
*
* @param object $source The XML source
* @param object $target The XML target
* @param string $elementname Name of the XML element of the target
*/
public static function copy(&$source, &$target, $elementname) {
if (count($source->children()) == 0)
$target->addChild($elementname, xmlify($source));
else {
$child = $target->addChild($elementname);
foreach ($source->children() AS $childfield => $childentry)
self::copy($childentry, $child, $childfield);
}
}
}
?>

View file

@ -427,8 +427,8 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
if(($contact) && ($contact['network'] === NETWORK_DIASPORA)) {
require_once('include/diaspora.php');
$ret = diaspora_share($user[0],$r[0]);
logger('mod_follow: diaspora_share returns: ' . $ret);
$ret = diaspora::send_share($user[0],$r[0]);
logger('share returns: ' . $ret);
}
// Send a new friend post if we are allowed to...

View file

@ -24,6 +24,7 @@ require_once('include/threads.php');
require_once('include/text.php');
require_once('include/items.php');
require_once('include/Scrape.php');
require_once('include/diaspora.php');
function item_post(&$a) {
@ -900,7 +901,7 @@ function item_post(&$a) {
// Store the comment signature information in case we need to relay to Diaspora
store_diaspora_comment_sig($datarray, $author, ($self ? $user['prvkey'] : false), $parent_item, $post_id);
diaspora::store_comment_signature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id);
} else {
$parent = $post_id;
@ -1245,42 +1246,3 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo
return array('replaced' => $replaced, 'contact' => $r[0]);
}
function store_diaspora_comment_sig($datarray, $author, $uprvkey, $parent_item, $post_id) {
// We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
$enabled = intval(get_config('system','diaspora_enabled'));
if(! $enabled) {
logger('mod_item: diaspora support disabled, not storing comment signature', LOGGER_DEBUG);
return;
}
logger('mod_item: storing diaspora comment signature');
require_once('include/bb2diaspora.php');
$signed_body = html_entity_decode(bb2diaspora($datarray['body']));
// Only works for NETWORK_DFRN
$contact_baseurl_start = strpos($author['url'],'://') + 3;
$contact_baseurl_length = strpos($author['url'],'/profile') - $contact_baseurl_start;
$contact_baseurl = substr($author['url'], $contact_baseurl_start, $contact_baseurl_length);
$diaspora_handle = $author['nick'] . '@' . $contact_baseurl;
$signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $diaspora_handle;
if( $uprvkey !== false )
$authorsig = rsa_sign($signed_text,$uprvkey,'sha256');
else
$authorsig = '';
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
intval($post_id),
dbesc($signed_text),
dbesc(base64_encode($authorsig)),
dbesc($diaspora_handle)
);
return;
}

View file

@ -28,14 +28,14 @@ function p_init($a){
$post = array();
$reshared = diaspora_is_reshare($item[0]["body"]);
$reshared = diaspora::is_reshare($item[0]["body"]);
if ($reshared) {
$nodename = "reshare";
$post["root_diaspora_id"] = $reshared["root_handle"];
$post["root_guid"] = $reshared["root_guid"];
$post["guid"] = $item[0]["guid"];
$post["diaspora_handle"] = diaspora_handle_from_contact($item[0]["contact-id"]);
$post["diaspora_handle"] = diaspora::handle_from_contact($item[0]["contact-id"]);
$post["public"] = (!$item[0]["private"] ? 'true':'false');
$post["created_at"] = datetime_convert('UTC','UTC',$item[0]["created"]);
} else {
@ -48,7 +48,7 @@ function p_init($a){
$nodename = "status_message";
$post["raw_message"] = str_replace("&", "&amp;", $body);
$post["guid"] = $item[0]["guid"];
$post["diaspora_handle"] = diaspora_handle_from_contact($item[0]["contact-id"]);
$post["diaspora_handle"] = diaspora::handle_from_contact($item[0]["contact-id"]);
$post["public"] = (!$item[0]["private"] ? 'true':'false');
$post["created_at"] = datetime_convert('UTC','UTC',$item[0]["created"]);
$post["provider_display_name"] = $item[0]["app"];

View file

@ -53,7 +53,7 @@ function receive_post(&$a) {
logger('mod-diaspora: message is okay', LOGGER_DEBUG);
$msg = diaspora_decode($importer,$xml);
$msg = diaspora::decode($importer,$xml);
logger('mod-diaspora: decoded', LOGGER_DEBUG);
@ -65,10 +65,11 @@ function receive_post(&$a) {
logger('mod-diaspora: dispatching', LOGGER_DEBUG);
$ret = 0;
if($public)
diaspora_dispatch_public($msg);
else
$ret = diaspora_dispatch($importer,$msg);
if($public) {
diaspora::dispatch_public($msg);
} else {
$ret = diaspora::dispatch($importer,$msg);
}
http_status_exit(($ret) ? $ret : 200);
// NOTREACHED

View file

@ -324,7 +324,7 @@ class Item extends BaseObject {
// Diaspora isn't able to do likes on comments - but red does
if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND
!diaspora_is_redmatrix($item["owner-link"]) AND isset($buttons["like"]))
!diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"]))
unset($buttons["like"]);
// Diaspora doesn't has multithreaded comments

94
util/createdoxygen.php Normal file
View file

@ -0,0 +1,94 @@
#!/usr/bin/php
<?php
/**
* @file util/createdoxygen.php
* @brief Adds a doxygen header to functions
*/
if (count($_SERVER["argv"]) < 2)
die("usage: createdoxygen.php file\n");
$file = $_SERVER["argv"][1];
$data = file_get_contents($file);
$lines = explode("\n", $data);
$previous = "";
foreach ($lines AS $line) {
$line = rtrim(trim($line, "\r"));
if (strstr(strtolower($line), "function")) {
$detect = strtolower(trim($line));
$detect = implode(" ", explode(" ", $detect));
$found = false;
if (substr($detect, 0, 9) == "function ")
$found = true;
if (substr($detect, 0, 17) == "private function ")
$found = true;
if (substr($detect, 0, 23) == "public static function ")
$found = true;
if (substr($detect, 0, 10) == "function (")
$found = false;
if ($found and (trim($previous) == "*/"))
$found = false;
if ($found and !strstr($detect, "{"))
$found = false;
if ($found) {
echo add_documentation($line);
}
}
echo $line."\n";
$previous = $line;
}
/**
* @brief Adds a doxygen header
*
* @param string $line The current line of the document
*
* @return string added doxygen header
*/
function add_documentation($line) {
$trimmed = ltrim($line);
$length = strlen($line) - strlen($trimmed);
$space = substr($line, 0, $length);
$block = $space."/**\n".
$space." * @brief \n".
$space." *\n"; /**/
$left = strpos($line, "(");
$line = substr($line, $left + 1);
$right = strpos($line, ")");
$line = trim(substr($line, 0, $right));
if ($line != "") {
$parameters = explode(",", $line);
foreach ($parameters AS $parameter) {
$parameter = trim($parameter);
$splitted = explode("=", $parameter);
$block .= $space." * @param ".trim($splitted[0], "& ")."\n";
}
if (count($parameters) > 0)
$block .= $space." *\n";
}
$block .= $space." * @return \n".
$space." */\n";
return $block;
}
?>

View file

@ -1,9 +0,0 @@
<decrypted_hdeader>
<iv>{{$inner_iv}}</iv>
<aes_key>{{$inner_key}}</aes_key>
<author>
<name>{{$author_name}}</name>
<uri>{{$author_uri}}</uri>
</author>
</decrypted_header>

View file

@ -1,12 +0,0 @@
<XML>
<post>
<comment>
<guid>{{$guid}}</guid>
<parent_guid>{{$parent_guid}}</parent_guid>
<author_signature>{{$authorsig}}</author_signature>
<text>{{$body}}</text>
<diaspora_handle>{{$handle}}</diaspora_handle>
</comment>
</post>
</XML>

View file

@ -1,13 +0,0 @@
<XML>
<post>
<comment>
<guid>{{$guid}}</guid>
<parent_guid>{{$parent_guid}}</parent_guid>
<parent_author_signature>{{$parentsig}}</parent_author_signature>
<author_signature>{{$authorsig}}</author_signature>
<text>{{$body}}</text>
<diaspora_handle>{{$handle}}</diaspora_handle>
</comment>
</post>
</XML>

View file

@ -1,30 +0,0 @@
<XML>
<post>
<conversation>
<guid>{{$conv.guid}}</guid>
<subject>{{$conv.subject}}</subject>
<created_at>{{$conv.created_at}}</created_at>
{{foreach $conv.messages as $msg}}
<message>
<guid>{{$msg.guid}}</guid>
<parent_guid>{{$msg.parent_guid}}</parent_guid>
{{if $msg.parent_author_signature}}
<parent_author_signature>{{$msg.parent_author_signature}}</parent_author_signature>
{{/if}}
<author_signature>{{$msg.author_signature}}</author_signature>
<text>{{$msg.text}}</text>
<created_at>{{$msg.created_at}}</created_at>
<diaspora_handle>{{$msg.diaspora_handle}}</diaspora_handle>
<conversation_guid>{{$msg.conversation_guid}}</conversation_guid>
</message>
{{/foreach}}
<diaspora_handle>{{$conv.diaspora_handle}}</diaspora_handle>
<participant_handles>{{$conv.participant_handles}}</participant_handles>
</conversation>
</post>
</XML>

View file

@ -1,13 +0,0 @@
<XML>
<post>
<like>
<positive>{{$positive}}</positive>
<guid>{{$guid}}</guid>
<target_type>{{$target_type}}</target_type>
<parent_guid>{{$parent_guid}}</parent_guid>
<author_signature>{{$authorsig}}</author_signature>
<diaspora_handle>{{$handle}}</diaspora_handle>
</like>
</post>
</XML>

View file

@ -1,14 +0,0 @@
<XML>
<post>
<like>
<positive>{{$positive}}</positive>
<guid>{{$guid}}</guid>
<target_type>{{$target_type}}</target_type>
<parent_guid>{{$parent_guid}}</parent_guid>
<parent_author_signature>{{$parentsig}}</parent_author_signature>
<author_signature>{{$authorsig}}</author_signature>
<diaspora_handle>{{$handle}}</diaspora_handle>
</like>
</post>
</XML>

View file

@ -1,17 +0,0 @@
<XML>
<post>
<message>
<guid>{{$msg.guid}}</guid>
<parent_guid>{{$msg.parent_guid}}</parent_guid>
{{if $msg.parent_author_signature}}
<parent_author_signature>{{$msg.parent_author_signature}}</parent_author_signature>
{{/if}}
<author_signature>{{$msg.author_signature}}</author_signature>
<text>{{$msg.text}}</text>
<created_at>{{$msg.created_at}}</created_at>
<diaspora_handle>{{$msg.diaspora_handle}}</diaspora_handle>
<conversation_guid>{{$msg.conversation_guid}}</conversation_guid>
</message>
</post>
</XML>

View file

@ -1,14 +0,0 @@
<XML>
<post>
<photo>
<guid>{{$guid}}</guid>
<diaspora_handle>{{$handle}}</diaspora_handle>
<public>{{$public}}</public>
<created_at>{{$created_at}}</created_at>
<remote_photo_path>{{$path}}</remote_photo_path>
<remote_photo_name>{{$filename}}</remote_photo_name>
<status_message_guid>{{$msg_guid}}</status_message_guid>
</photo>
</post>
</XML>

View file

@ -1,13 +0,0 @@
<XML>
<post>
<status_message>
<raw_message>{{$body}}</raw_message>
<guid>{{$guid}}</guid>
<diaspora_handle>{{$handle}}</diaspora_handle>
<public>{{$public}}</public>
<created_at>{{$created}}</created_at>
<provider_display_name>{{$provider}}</provider_display_name>
</status_message>
</post>
</XML>

View file

@ -1,17 +0,0 @@
<XML>
<post><profile>
<diaspora_handle>{{$handle}}</diaspora_handle>
<first_name>{{$first}}</first_name>
<last_name>{{$last}}</last_name>
<image_url>{{$large}}</image_url>
<image_url_medium>{{$medium}}</image_url_medium>
<image_url_small>{{$small}}</image_url_small>
<birthday>{{$dob}}</birthday>
<gender>{{$gender}}</gender>
<bio>{{$about}}</bio>
<location>{{$location}}</location>
<searchable>{{$searchable}}</searchable>
<tag_string>{{$tags}}</tag_string>
</profile></post>
</XML>

View file

@ -1,11 +0,0 @@
<XML>
<post>
<relayable_retraction>
<target_type>{{$type}}</target_type>
<target_guid>{{$guid}}</target_guid>
<target_author_signature>{{$signature}}</target_author_signature>
<sender_handle>{{$handle}}</sender_handle>
</relayable_retraction>
</post>
</XML>

View file

@ -1,12 +0,0 @@
<XML>
<post>
<relayable_retraction>
<parent_author_signature>{{$parentsig}}</parent_author_signature>
<target_guid>{{$guid}}</target_guid>
<target_type>{{$target_type}}</target_type>
<sender_handle>{{$handle}}</sender_handle>
<target_author_signature>{{$authorsig}}</target_author_signature>
</relayable_retraction>
</post>
</XML>

View file

@ -1,14 +0,0 @@
<XML>
<post>
<reshare>
<root_diaspora_id>{{$root_handle}}</root_diaspora_id>
<root_guid>{{$root_guid}}</root_guid>
<guid>{{$guid}}</guid>
<diaspora_handle>{{$handle}}</diaspora_handle>
<public>{{$public}}</public>
<created_at>{{$created}}</created_at>
<provider_display_name>{{$provider}}</provider_display_name>
</reshare>
</post>
</XML>

View file

@ -1,10 +0,0 @@
<XML>
<post>
<retraction>
<post_guid>{{$guid}}</post_guid>
<diaspora_handle>{{$handle}}</diaspora_handle>
<type>{{$type}}</type>
</retraction>
</post>
</XML>

View file

@ -1,9 +0,0 @@
<XML>
<post>
<request>
<sender_handle>{{$sender}}</sender_handle>
<recipient_handle>{{$recipient}}</recipient_handle>
</request>
</post>
</XML>

View file

@ -1,11 +0,0 @@
<XML>
<post>
<signed_retraction>
<target_guid>{{$guid}}</target_guid>
<target_type>{{$type}}</target_type>
<sender_handle>{{$handle}}</sender_handle>
<target_author_signature>{{$signature}}</target_author_signature>
</signed_retraction>
</post>
</XML>