aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/dba.php48
-rw-r--r--include/diaspora.php168
2 files changed, 202 insertions, 14 deletions
diff --git a/include/dba.php b/include/dba.php
index e9d47cd1a..3fa615d90 100644
--- a/include/dba.php
+++ b/include/dba.php
@@ -16,8 +16,10 @@ class dba {
private $debug = 0;
private $db;
+ public $mysqli = true;
public $connected = false;
+
function __construct($server,$user,$pass,$db,$install = false) {
$server = trim($server);
@@ -43,6 +45,7 @@ class dba {
}
}
else {
+ $this->mysqli = false;
$this->db = mysql_connect($server,$user,$pass);
if($this->db && mysql_select_db($db,$this->db)) {
$this->connected = true;
@@ -64,7 +67,7 @@ class dba {
if((! $this->db) || (! $this->connected))
return false;
- if(class_exists('mysqli'))
+ if($this->mysqli)
$result = @$this->db->query($sql);
else
$result = @mysql_query($sql,$this->db);
@@ -73,7 +76,7 @@ class dba {
$mesg = '';
- if(class_exists('mysqli') && $this->db->errno)
+ if($this->mysqli && $this->db->errno)
logger('dba: ' . $this->db->error);
else
logger('dba: ' . mysql_error($this->db));
@@ -82,9 +85,13 @@ class dba {
$mesg = 'false';
elseif($result === true)
$mesg = 'true';
- else
- $mesg = $result->num_rows . ' results' . EOL;
-
+ else {
+ if($this->mysqli)
+ $mesg = $result->num_rows . ' results' . EOL;
+ else
+ $mesg = mysql_num_rows($result) . ' results' . EOL;
+ }
+
$str = 'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg . EOL;
logger('dba: ' . $str );
@@ -108,11 +115,21 @@ class dba {
return $result;
$r = array();
- if($result->num_rows) {
- while($x = $result->fetch_array(MYSQL_ASSOC))
- $r[] = $x;
- $result->free_result();
+ if($this->mysqli) {
+ if($result->num_rows) {
+ while($x = $result->fetch_array(MYSQL_ASSOC))
+ $r[] = $x;
+ $result->free_result();
+ }
+ }
+ else {
+ if(mysql_num_rows($result)) {
+ while($x = mysql_fetch_array($result, MYSQL_ASSOC))
+ $r[] = $x;
+ mysql_free_result($result);
+ }
}
+
if($this->debug)
logger('dba: ' . printable(print_r($r, true)), LOGGER_DATA);
@@ -124,12 +141,19 @@ class dba {
}
public function escape($str) {
- if($this->db && $this->connected)
- return @$this->db->real_escape_string($str);
+ if($this->db && $this->connected) {
+ if($this->mysqli)
+ return @$this->db->real_escape_string($str);
+ else
+ return @mysql_real_escape_string($str,$this->db);
+ }
}
function __destruct() {
- @$this->db->close();
+ if($this->mysqli)
+ @$this->db->close();
+ else
+ @mysql_close($this->db);
}
}}
diff --git a/include/diaspora.php b/include/diaspora.php
index 0ffb22b95..07d454e45 100644
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -71,6 +71,9 @@ function diaspora_dispatch($importer,$msg) {
elseif($xmlbase->photo) {
$ret = diaspora_photo($importer,$xmlbase->photo,$msg);
}
+ elseif($xmlbase->conversation) {
+ $ret = diaspora_conversation($importer,$xmlbase->conversation,$msg);
+ }
else {
logger('diaspora_dispatch: unknown message type: ' . print_r($xmlbase,true));
}
@@ -902,8 +905,6 @@ function diaspora_comment($importer,$xml,$msg) {
$parent_author_signature = (($xml->parent_author_signature) ? notags(unxmlify($xml->parent_author_signature)) : '');
- $text = $xml->text;
-
$contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']);
if(! $contact) {
logger('diaspora_comment: cannot find contact: ' . $msg['author']);
@@ -1050,6 +1051,169 @@ function diaspora_comment($importer,$xml,$msg) {
return;
}
+
+
+
+function diaspora_conversation($importer,$xml,$msg) {
+
+ $a = get_app();
+
+ $guid = notags(unxmlify($xml->guid));
+ $subject = notags(unxmlify($xml->subject));
+ $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
+ $participant_handles = notags(unxmlify($xml->participant_handles));
+ $created_at = datetime_convert('UTC','UTC',notags(unxmlify($xml->created_at)));
+
+ $parent_uri = $diaspora_handle . ':' . $guid;
+
+ $messages = $xml->message;
+
+ if(! count($messages)) {
+ logger('diaspora_conversation: empty conversation');
+ return;
+ }
+
+ $contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']);
+ if(! $contact) {
+ logger('diaspora_conversation: cannot find contact: ' . $msg['author']);
+ return;
+ }
+
+ if(($contact['rel'] == CONTACT_IS_FOLLOWER) || ($contact['blocked']) || ($contact['readonly'])) {
+ logger('diaspora_conversation: Ignoring this author.');
+ return 202;
+ }
+
+ foreach($messages as $msg) {
+ $msg_guid = notags(unxmlify($msg->guid));
+ $msg_parent_guid = notags(unxmlify($msg->parent_guid));
+ $msg_parent_author_signature = notags(unxmlify($msg->parent_author_signature));
+ $msg_author_signature = notags(unxmlify($msg->author_signature));
+ $msg_text = unxmlify($msg->text);
+ $msg_created_at = datetime_convert('UTC','UTC',notags(unxmlify($msg->created_at)));
+ $msg_diaspora_handle = notags(unxmlify($msg->diaspora_handle));
+ $msg_conversation_guid = notags(unxmlify($msg->conversation_guid));
+ if($msg_conversation_guid != $guid) {
+ logger('diaspora_conversation: message conversation guid does not belong to the current conversation. ' . $xml);
+ continue;
+ }
+
+
+ $body = diaspora2bb($msg_text);
+ $message_id = $msg_diaspora_handle . ':' . $msg_guid;
+
+ $person = find_diaspora_person_by_handle($msg_diaspora_handle);
+ if(is_array($person) && x($person,'pubkey'))
+ $key = $person['pubkey'];
+ else {
+ logger('diaspora_conversation: unable to find author details');
+ continue;
+ }
+
+ $r = q("select id from mail where `uri` = '%s' limit 1",
+ dbesc($message_id)
+ );
+ if(count($r)) {
+ logger('diaspora_conversation: duplicate message already delivered.', LOGGER_DEBUG);
+ continue;
+ }
+
+
+ // don't forget guid, convid!!!
+
+ q("insert into mail ( `uid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`replied`,`uri`,`parent-uri`,`created`) values ( %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
+ intval($importer['uid']),
+ dbesc($person['name']),
+ dbesc($person['photo']),
+ dbesc($person['url']),
+ intval($contact['id']),
+ dbesc($subject),
+ dbesc($body),
+ 0,
+ 0,
+ dbesc($message_id),
+ dbesc($parent_uri),
+ dbesc($msg_created_at)
+ );
+
+ }
+
+
+/*
+ $author_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $diaspora_handle;
+
+ $author_signature = base64_decode($author_signature);
+
+ if(strcasecmp($diaspora_handle,$msg['author']) == 0) {
+ $person = $contact;
+ $key = $msg['key'];
+ }
+ else {
+ $person = find_diaspora_person_by_handle($diaspora_handle);
+
+ if(is_array($person) && x($person,'pubkey'))
+ $key = $person['pubkey'];
+ else {
+ logger('diaspora_comment: unable to find author details');
+ return;
+ }
+ }
+
+ if(! rsa_verify($author_signed_data,$author_signature,$key,'sha256')) {
+ logger('diaspora_comment: verification failed.');
+ return;
+ }
+
+ if($parent_author_signature) {
+ $owner_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $diaspora_handle;
+
+ $parent_author_signature = base64_decode($parent_author_signature);
+
+ $key = $msg['key'];
+
+ if(! rsa_verify($owner_signed_data,$parent_author_signature,$key,'sha256')) {
+ logger('diaspora_comment: owner verification failed.');
+ return;
+ }
+ }
+
+ // Phew! Everything checks out. Now create an item.
+
+ $body = diaspora2bb($text);
+
+ $message_id = $diaspora_handle . ':' . $guid;
+
+ $datarray = array();
+
+ $str_tags = '';
+
+ $tags = get_tags($body);
+
+ if(count($tags)) {
+ foreach($tags as $tag) {
+ if(strpos($tag,'#') === 0) {
+ if(strpos($tag,'[url='))
+ continue;
+ $basetag = str_replace('_',' ',substr($tag,1));
+ $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
+ if(strlen($str_tags))
+ $str_tags .= ',';
+ $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
+ continue;
+ }
+ }
+ }
+
+*/
+
+ return;
+}
+
+
+
+
+
+
function diaspora_photo($importer,$xml,$msg) {
$a = get_app();