';
+ else
+ return $s[0];
+}
-function bb2diaspora($Text,$preserve_nl = false) {
+
+function diaspora_ol($s) {
+ // A hack: Diaspora will create a properly-numbered ordered list even
+ // if you use '1.' for each element of the list, like:
+ // 1. First element
+ // 1. Second element
+ // 1. Third element
+ if( strpos($s[0], "[list=1]") === 0 )
+ return '
';
+ else
+ return $s[0];
+}
+*/
+
+//////////////////////
+// Non-Markdownify versions of "diaspora_ol" and "diaspora_ul"
+//////////////////////
+function diaspora_ul($s) {
+ // Replace "[\\*]" followed by any number (including zero) of
+ // spaces by "* " to match Diaspora's list format
+ return preg_replace("/\[\\\\\*\]( *)/", "* ", $s[1]);
+}
+
+function diaspora_ol($s) {
+ // A hack: Diaspora will create a properly-numbered ordered list even
+ // if you use '1.' for each element of the list, like:
+ // 1. First element
+ // 1. Second element
+ // 1. Third element
+ return preg_replace("/\[\\\\\*\]( *)/", "1. ", $s[1]);
+}
+
+
+function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
+
+ // Re-enabling the converter again.
+ // The bbcode parser now handles youtube-links (and the other stuff) correctly.
+ // Additionally the html code is now fixed so that lists are now working.
+
+ /**
+ * Transform #tags, strip off the [url] and replace spaces with underscore
+ */
+ $Text = preg_replace_callback('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', create_function('$match',
+ 'return \'#\'. str_replace(\' \', \'_\', $match[2]);'
+ ), $Text);
+
+
+ // Converting images with size parameters to simple images. Markdown doesn't know it.
+ $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $Text);
+
+ // the following was added on 10-January-2012 due to an inability of Diaspora's
+ // new javascript markdown processor to handle links with images as the link "text"
+ // It is not optimal and may be removed if this ability is restored in the future
+ //if ($fordiaspora)
+ // $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism",
+ // "[url]$1[/url]\n[img]$2[/img]", $Text);
+
+ // Convert it to HTML - don't try oembed
+ $Text = bbcode($Text, $preserve_nl, false);
+
+ // Now convert HTML to Markdown
+ $md = new Markdownify(false, false, false);
+ $Text = $md->parseString($Text);
+
+ // The Markdownify converter converts underscores '_' in URLs to '\_', which
+ // messes up the URL. Manually fix these
+ $count = 1;
+ $pos = bb_find_open_close($Text, '[', ']', $count);
+ while($pos !== false) {
+ $start = substr($Text, 0, $pos['start']);
+ $subject = substr($Text, $pos['start'], $pos['end'] - $pos['start'] + 1);
+ $end = substr($Text, $pos['end'] + 1);
+
+ $subject = str_replace('\_', '_', $subject);
+ $Text = $start . $subject . $end;
+
+ $count++;
+ $pos = bb_find_open_close($Text, '[', ']', $count);
+ }
+
+ // If the text going into bbcode() has a plain URL in it, i.e.
+ // with no [url] tags around it, it will come out of parseString()
+ // looking like: , which gets removed by strip_tags().
+ // So take off the angle brackets of any such URL
+ $Text = preg_replace("//is", "http$1", $Text);
+
+ // Remove all unconverted tags
+ $Text = strip_tags($Text);
+
+
+/* Old routine
$ev = bbtoevent($Text);
@@ -78,12 +199,17 @@ function bb2diaspora($Text,$preserve_nl = false) {
$Text = str_replace(">", ">", $Text);
// If we find any event code, turn it into an event.
- // After we're finished processing the bbcode we'll
+ // After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version.
-
if($preserve_nl)
$Text = str_replace(array("\n","\r"), array('',''),$Text);
+ else
+ // Remove the "return" character, as Diaspora uses only the "newline"
+ // character, so having the "return" character can cause signature
+ // failures
+ $Text = str_replace("\r", "", $Text);
+
// Set up the parameters for a URL search string
$URLSearchString = "^\[\]";
@@ -98,7 +224,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
// new javascript markdown processor to handle links with images as the link "text"
// It is not optimal and may be removed if this ability is restored in the future
- $Text = preg_replace("/\[url\=([$URLSearchString]*)\]\[img\](.*?)\[\/img\]\[\/url\]/ism",
+ $Text = preg_replace("/\[url\=([$URLSearchString]*)\]\[img\](.*?)\[\/img\]\[\/url\]/ism",
'![' . t('image/photo') . '](' . '$2' . ')' . "\n" . '[' . t('link') . '](' . '$1' . ')', $Text);
$Text = preg_replace("/\[bookmark\]([$URLSearchString]*)\[\/bookmark\]/ism", '[$1]($1)', $Text);
@@ -115,7 +241,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
// Perform MAIL Search
$Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text);
$Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '[$2](mailto:$1)', $Text);
-
+
$Text = str_replace('*', '\\*', $Text);
$Text = str_replace('_', '\\_', $Text);
@@ -124,48 +250,61 @@ function bb2diaspora($Text,$preserve_nl = false) {
// Check for bold text
$Text = preg_replace("(\[b\](.*?)\[\/b\])is",'**$1**',$Text);
- // Check for Italics text
+ // Check for italics text
$Text = preg_replace("(\[i\](.*?)\[\/i\])is",'_$1_',$Text);
- // Check for Underline text
-// $Text = preg_replace("(\[u\](.*?)\[\/u\])is",'$1',$Text);
+ // Check for underline text
+ // Replace with italics since Diaspora doesn't have underline
+ $Text = preg_replace("(\[u\](.*?)\[\/u\])is",'_$1_',$Text);
// Check for strike-through text
-// $Text = preg_replace("(\[s\](.*?)\[\/s\])is",'$1',$Text);
+ $Text = preg_replace("(\[s\](.*?)\[\/s\])is",'**[strike]**$1**[/strike]**',$Text);
// Check for over-line text
// $Text = preg_replace("(\[o\](.*?)\[\/o\])is",'$1',$Text);
// Check for colored text
-// $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])is","$2",$Text);
+ // Remove color since Diaspora doesn't support it
+ $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])is","$2",$Text);
// Check for sized text
-// $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])is","$2",$Text);
+ // Remove it since Diaspora doesn't support sizes very well
+ $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])is","$2",$Text);
// Check for list text
-// $Text = preg_replace("/\[list\](.*?)\[\/list\]/is", '
';
-
+
}
return $o;
}
+function get_item_children($arr, $parent) {
+ $children = array();
+ foreach($arr as $item) {
+ if($item['id'] != $item['parent']) {
+ if(get_config('system','thread_allow')) {
+ // Fallback to parent-uri if thr-parent is not set
+ $thr_parent = $item['thr-parent'];
+ if($thr_parent == '')
+ $thr_parent = $item['parent-uri'];
+
+ if($thr_parent == $parent['uri']) {
+ $item['children'] = get_item_children($arr, $item);
+ $children[] = $item;
+ }
+ }
+ else if($item['parent'] == $parent['id']) {
+ $children[] = $item;
+ }
+ }
+ }
+ return $children;
+}
+
+function sort_item_children($items) {
+ $result = $items;
+ usort($result,'sort_thr_created_rev');
+ foreach($result as $k => $i) {
+ if(count($result[$k]['children'])) {
+ $result[$k]['children'] = sort_item_children($result[$k]['children']);
+ }
+ }
+ return $result;
+}
+
+function add_children_to_list($children, &$arr) {
+ foreach($children as $y) {
+ $arr[] = $y;
+ if(count($y['children']))
+ add_children_to_list($y['children'], $arr);
+ }
+}
+
function conv_sort($arr,$order) {
if((!(is_array($arr) && count($arr))))
return array();
$parents = array();
+ $children = array();
foreach($arr as $x)
if($x['id'] == $x['parent'])
@@ -1053,24 +1360,25 @@ function conv_sort($arr,$order) {
usort($parents,'sort_thr_commented');
if(count($parents))
- foreach($parents as $i=>$_x)
- $parents[$i]['children'] = array();
+ foreach($parents as $i=>$_x)
+ $parents[$i]['children'] = get_item_children($arr, $_x);
- foreach($arr as $x) {
+ /*foreach($arr as $x) {
if($x['id'] != $x['parent']) {
$p = find_thread_parent_index($parents,$x);
if($p !== false)
$parents[$p]['children'][] = $x;
}
- }
+ }*/
if(count($parents)) {
foreach($parents as $k => $v) {
if(count($parents[$k]['children'])) {
- $y = $parents[$k]['children'];
+ $parents[$k]['children'] = sort_item_children($parents[$k]['children']);
+ /*$y = $parents[$k]['children'];
usort($y,'sort_thr_created_rev');
- $parents[$k]['children'] = $y;
+ $parents[$k]['children'] = $y;*/
}
- }
+ }
}
$ret = array();
@@ -1078,8 +1386,9 @@ function conv_sort($arr,$order) {
foreach($parents as $x) {
$ret[] = $x;
if(count($x['children']))
- foreach($x['children'] as $y)
- $ret[] = $y;
+ add_children_to_list($x['children'], $ret);
+ /*foreach($x['children'] as $y)
+ $ret[] = $y;*/
}
}
diff --git a/include/crypto.php b/include/crypto.php
index 6fc9a287e..ed0a35704 100644
--- a/include/crypto.php
+++ b/include/crypto.php
@@ -261,39 +261,6 @@ function aes_unencapsulate($data,$prvkey) {
return AES256CBC_decrypt(base64url_decode($data['data']),$k,$i);
}
-
-// This has been superceded.
-
-function zot_encapsulate($data,$envelope,$pubkey) {
-$res = aes_encapsulate($data,$pubkey);
-
-return <<< EOT
-
-
- {$res['key']}
- {$res['iv']}
- $s1
- $sig
- AES-256-CBC
- {$res['data']}
-
-EOT;
-
-}
-
-// so has this
-
-function zot_unencapsulate($data,$prvkey) {
- $ret = array();
- $c = array();
- $x = parse_xml_string($data);
- $c = array('key' => $x->key,'iv' => $x->iv,'data' => $x->data);
- openssl_private_decrypt(base64url_decode($x->sender),$s,$prvkey);
- $ret['sender'] = $s;
- $ret['data'] = aes_unencapsulate($x,$prvkey);
- return $ret;
-}
-
function new_keypair($bits) {
$openssl_options = array(
diff --git a/include/datetime.php b/include/datetime.php
index 58a618610..efcfa0a17 100644
--- a/include/datetime.php
+++ b/include/datetime.php
@@ -100,11 +100,33 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
return str_replace('1','0',$d->format($fmt));
}
- $d = new DateTime($s, new DateTimeZone($from));
- $d->setTimeZone(new DateTimeZone($to));
+ try {
+ $from_obj = new DateTimeZone($from);
+ }
+ catch(Exception $e) {
+ $from_obj = new DateTimeZone('UTC');
+ }
+
+ try {
+ $d = new DateTime($s, $from_obj);
+ }
+ catch(Exception $e) {
+ logger('datetime_convert: exception: ' . $e->getMessage());
+ $d = new DateTime('now', $from_obj);
+ }
+
+ try {
+ $to_obj = new DateTimeZone($to);
+ }
+ catch(Exception $e) {
+ $to_obj = new DateTimeZone('UTC');
+ }
+
+ $d->setTimeZone($to_obj);
return($d->format($fmt));
}}
+
// wrapper for date selector, tailored for use in birthday fields
function dob($dob) {
@@ -447,11 +469,13 @@ function update_contact_birthdays() {
*
*/
- $bdtext = t('Birthday:') . ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]' ;
+ $bdtext = sprintf( t('%s\'s birthday'), $rr['name']);
+ $bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]') ;
- $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`desc`,`type`,`adjust`)
- VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ",
+
+ $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`,`adjust`)
+ VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ",
intval($rr['uid']),
intval($rr['id']),
dbesc(datetime_convert()),
@@ -459,6 +483,7 @@ function update_contact_birthdays() {
dbesc(datetime_convert('UTC','UTC', $nextbd)),
dbesc(datetime_convert('UTC','UTC', $nextbd . ' + 1 day ')),
dbesc($bdtext),
+ dbesc($bdtext2),
dbesc('birthday'),
intval(0)
);
diff --git a/include/dba.php b/include/dba.php
index 881097f30..8d224b570 100644
--- a/include/dba.php
+++ b/include/dba.php
@@ -71,22 +71,32 @@ class dba {
}
public function q($sql) {
+ global $a;
if((! $this->db) || (! $this->connected))
return false;
$this->error = '';
- //if (get_config("system", "db_log") != "")
- // @file_put_contents(get_config("system", "db_log"), datetime_convert().':'.session_id(). ' Start '.$sql."\n", FILE_APPEND);
+ if(x($a->config,'system') && x($a->config['system'],'db_log'))
+ $stamp1 = microtime(true);
if($this->mysqli)
$result = @$this->db->query($sql);
else
$result = @mysql_query($sql,$this->db);
- //if (get_config("system", "db_log") != "")
- // @file_put_contents(get_config("system", "db_log"), datetime_convert().':'.session_id(). ' Stop '."\n", FILE_APPEND);
+ if(x($a->config,'system') && x($a->config['system'],'db_log')) {
+ $stamp2 = microtime(true);
+ $duration = round($stamp2-$stamp1, 3);
+ if ($duration > $a->config["system"]["db_loglimit"]) {
+ $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+ @file_put_contents($a->config["system"]["db_log"], $duration."\t".
+ basename($backtrace[1]["file"])."\t".
+ $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
+ substr($sql, 0, 2000)."\n", FILE_APPEND);
+ }
+ }
if($this->mysqli) {
if($this->db->errno)
@@ -275,3 +285,9 @@ function dbesc_array(&$arr) {
array_walk($arr,'dbesc_array_cb');
}
}}
+
+
+function dba_timer() {
+ return microtime(true);
+}
+
diff --git a/include/delivery.php b/include/delivery.php
index e6cfc8155..14226e4fb 100644
--- a/include/delivery.php
+++ b/include/delivery.php
@@ -113,7 +113,7 @@ function delivery_run($argv, $argc){
$uid = $r[0]['uid'];
$updated = $r[0]['edited'];
- // The following seems superfluous. We've already checked for "if (! intval($r[0]['parent']))" a few lines up
+ // POSSIBLE CLEANUP --> The following seems superfluous. We've already checked for "if (! intval($r[0]['parent']))" a few lines up
if(! $parent_id)
continue;
@@ -280,7 +280,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'] == 1)
continue;
$item_contact = get_item_contact($item,$icontacts);
@@ -328,8 +328,9 @@ function delivery_run($argv, $argc){
dbesc($nickname)
);
- if(count($x)) {
- if($owner['page-flags'] == PAGE_COMMUNITY && ! $x[0]['writable']) {
+ 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 limit 1",
intval($x[0]['id'])
);
@@ -383,7 +384,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'] == 1)
continue;
$item_contact = get_item_contact($item,$icontacts);
diff --git a/include/diaspora.php b/include/diaspora.php
index 2be266e8a..baee0420b 100755
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -5,6 +5,7 @@ require_once('include/items.php');
require_once('include/bb2diaspora.php');
require_once('include/contact_selectors.php');
require_once('include/queue_fn.php');
+require_once('include/lock.php');
function diaspora_dispatch_public($msg) {
@@ -60,10 +61,10 @@ function diaspora_dispatch($importer,$msg) {
$ret = diaspora_request($importer,$xmlbase->request);
}
elseif($xmlbase->status_message) {
- $ret = diaspora_post($importer,$xmlbase->status_message);
+ $ret = diaspora_post($importer,$xmlbase->status_message,$msg);
}
elseif($xmlbase->profile) {
- $ret = diaspora_profile($importer,$xmlbase->profile);
+ $ret = diaspora_profile($importer,$xmlbase->profile,$msg);
}
elseif($xmlbase->comment) {
$ret = diaspora_comment($importer,$xmlbase->comment,$msg);
@@ -72,10 +73,10 @@ function diaspora_dispatch($importer,$msg) {
$ret = diaspora_like($importer,$xmlbase->like,$msg);
}
elseif($xmlbase->asphoto) {
- $ret = diaspora_asphoto($importer,$xmlbase->asphoto);
+ $ret = diaspora_asphoto($importer,$xmlbase->asphoto,$msg);
}
elseif($xmlbase->reshare) {
- $ret = diaspora_reshare($importer,$xmlbase->reshare);
+ $ret = diaspora_reshare($importer,$xmlbase->reshare,$msg);
}
elseif($xmlbase->retraction) {
$ret = diaspora_retraction($importer,$xmlbase->retraction,$msg);
@@ -101,6 +102,37 @@ function diaspora_dispatch($importer,$msg) {
return $ret;
}
+function diaspora_handle_from_contact($contact_id) {
+ $handle = False;
+
+ logger("diaspora_handle_from_contact: contact id is " . $contact_id, LOGGER_DEBUG);
+
+ $r = q("SELECT network, addr, self, url, nick FROM contact WHERE id = %d",
+ intval($contact_id)
+ );
+ if($r) {
+ $contact = $r[0];
+
+ logger("diaspora_handle_from_contact: contact 'self' = " . $contact['self'] . " 'url' = " . $contact['url'], LOGGER_DEBUG);
+
+ if($contact['network'] === NETWORK_DIASPORA) {
+ $handle = $contact['addr'];
+
+// logger("diaspora_handle_from_contact: contact id is a Diaspora person, handle = " . $handle, LOGGER_DEBUG);
+ }
+ elseif(($contact['network'] === NETWORK_DFRN) || ($contact['self'] == 1)) {
+ $baseurl_start = strpos($contact['url'],'://') + 3;
+ $baseurl_length = strpos($contact['url'],'/profile') - $baseurl_start; // allows installations in a subdirectory--not sure how Diaspora will handle
+ $baseurl = substr($contact['url'], $baseurl_start, $baseurl_length);
+ $handle = $contact['nick'] . '@' . $baseurl;
+
+// logger("diaspora_handle_from_contact: contact id is a DFRN person, handle = " . $handle, LOGGER_DEBUG);
+ }
+ }
+
+ return $handle;
+}
+
function diaspora_get_contact_by_handle($uid,$handle) {
$r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `addr` = '%s' LIMIT 1",
dbesc(NETWORK_DIASPORA),
@@ -113,27 +145,93 @@ function diaspora_get_contact_by_handle($uid,$handle) {
}
function find_diaspora_person_by_handle($handle) {
+
+ $person = false;
$update = false;
- $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1",
- dbesc(NETWORK_DIASPORA),
- dbesc($handle)
- );
- if(count($r)) {
- logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DEBUG);
- // update record occasionally so it doesn't get stale
- $d = strtotime($r[0]['updated'] . ' +00:00');
- if($d > strtotime('now - 14 days'))
- return $r[0];
- $update = true;
- }
- logger('find_diaspora_person_by_handle: refresh',LOGGER_DEBUG);
- require_once('include/Scrape.php');
- $r = probe_url($handle, PROBE_DIASPORA);
- if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) {
- add_fcontact($r,$update);
- return ($r);
- }
- return false;
+ $got_lock = false;
+
+ $endlessloop = 0;
+ $maxloops = 10;
+
+ do {
+ $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1",
+ dbesc(NETWORK_DIASPORA),
+ dbesc($handle)
+ );
+ if(count($r)) {
+ $person = $r[0];
+ logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DEBUG);
+
+ // update record occasionally so it doesn't get stale
+ $d = strtotime($person['updated'] . ' +00:00');
+ if($d < strtotime('now - 14 days'))
+ $update = true;
+ }
+
+
+ // FETCHING PERSON INFORMATION FROM REMOTE SERVER
+ //
+ // If the person isn't in our 'fcontact' table, or if he/she is but
+ // his/her information hasn't been updated for more than 14 days, then
+ // we want to fetch the person's information from the remote server.
+ //
+ // Note that $person isn't changed by this block of code unless the
+ // person's information has been successfully fetched from the remote
+ // server. So if $person was 'false' to begin with (because he/she wasn't
+ // in the local cache), it'll stay false, and if $person held the local
+ // cache information to begin with, it'll keep that information. That way
+ // if there's a problem with the remote fetch, we can at least use our
+ // cached information--it's better than nothing.
+
+ if((! $person) || ($update)) {
+ // Lock the function to prevent race conditions if multiple items
+ // come in at the same time from a person who doesn't exist in
+ // fcontact
+ //
+ // Don't loop forever. On the last loop, try to create the contact
+ // whether the function is locked or not. Maybe the locking thread
+ // has died or something. At any rate, a duplicate in 'fcontact'
+ // is a much smaller problem than a deadlocked thread
+ $got_lock = lock_function('find_diaspora_person_by_handle', false);
+ if(($endlessloop + 1) >= $maxloops)
+ $got_lock = true;
+
+ if($got_lock) {
+ logger('find_diaspora_person_by_handle: create or refresh', LOGGER_DEBUG);
+ require_once('include/Scrape.php');
+ $r = probe_url($handle, PROBE_DIASPORA);
+
+ // Note that Friendica contacts can return a "Diaspora person"
+ // if Diaspora connectivity is enabled on their server
+ if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) {
+ add_fcontact($r,$update);
+ $person = ($r);
+ }
+
+ unlock_function('find_diaspora_person_by_handle');
+ }
+ else {
+ logger('find_diaspora_person_by_handle: couldn\'t lock function', LOGGER_DEBUG);
+ if(! $person)
+ block_on_function_lock('find_diaspora_person_by_handle');
+ }
+ }
+ } while((! $person) && (! $got_lock) && (++$endlessloop < $maxloops));
+ // We need to try again if the person wasn't in 'fcontact' but the function was locked.
+ // The fact that the function was locked may mean that another process was creating the
+ // person's record. It could also mean another process was creating or updating an unrelated
+ // person.
+ //
+ // At any rate, we need to keep trying until we've either got the person or had a chance to
+ // try to fetch his/her remote information. But we don't want to block on locking the
+ // function, because if the other process is creating the record, then when we acquire the lock
+ // we'll dive right into creating another, duplicate record. We DO want to at least wait
+ // until the lock is released, so we don't flood the database with requests.
+ //
+ // If the person was in the 'fcontact' table, don't try again. It's not worth the time, since
+ // we do have some information for the person
+
+ return $person;
}
@@ -654,12 +752,17 @@ function diaspora_post_allow($importer,$contact) {
}
-function diaspora_post($importer,$xml) {
+function diaspora_post($importer,$xml,$msg) {
$a = get_app();
$guid = notags(unxmlify($xml->guid));
$diaspora_handle = notags(unxmlify($xml->diaspora_handle));
+ if($diaspora_handle != $msg['author']) {
+ logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.');
+ return 202;
+ }
+
$contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
if(! $contact)
return;
@@ -770,7 +873,7 @@ function diaspora_post($importer,$xml) {
}
-function diaspora_reshare($importer,$xml) {
+function diaspora_reshare($importer,$xml,$msg) {
logger('diaspora_reshare: init: ' . print_r($xml,true));
@@ -779,6 +882,11 @@ function diaspora_reshare($importer,$xml) {
$diaspora_handle = notags(unxmlify($xml->diaspora_handle));
+ if($diaspora_handle != $msg['author']) {
+ logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.');
+ return 202;
+ }
+
$contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
if(! $contact)
return;
@@ -844,7 +952,7 @@ function diaspora_reshare($importer,$xml) {
else
$details = $orig_author;
- $prefix = '♲ ' . $details . "\n";
+ $prefix = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8') . $details . "\n";
// allocate a guid on our system - we aren't fixing any collisions.
@@ -924,13 +1032,18 @@ function diaspora_reshare($importer,$xml) {
}
-function diaspora_asphoto($importer,$xml) {
+function diaspora_asphoto($importer,$xml,$msg) {
logger('diaspora_asphoto called');
$a = get_app();
$guid = notags(unxmlify($xml->guid));
$diaspora_handle = notags(unxmlify($xml->diaspora_handle));
+ if($diaspora_handle != $msg['author']) {
+ logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.');
+ return 202;
+ }
+
$contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
if(! $contact)
return;
@@ -1154,6 +1267,7 @@ function diaspora_comment($importer,$xml,$msg) {
$datarray['uid'] = $importer['uid'];
$datarray['contact-id'] = $contact['id'];
+ $datarray['type'] = 'remote-comment';
$datarray['wall'] = $parent_item['wall'];
$datarray['gravity'] = GRAVITY_COMMENT;
$datarray['guid'] = $guid;
@@ -1190,7 +1304,7 @@ function diaspora_comment($importer,$xml,$msg) {
if(($parent_item['origin']) && (! $parent_author_signature)) {
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
intval($message_id),
- dbesc($author_signed_data),
+ dbesc($signed_data),
dbesc(base64_encode($author_signature)),
dbesc($diaspora_handle)
);
@@ -1199,7 +1313,7 @@ function diaspora_comment($importer,$xml,$msg) {
// the existence of parent_author_signature means the parent_author or owner
// is already relaying.
- proc_run('php','include/notifier.php','comment',$message_id);
+ proc_run('php','include/notifier.php','comment-import',$message_id);
}
$myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0 ",
@@ -1236,7 +1350,7 @@ function diaspora_comment($importer,$xml,$msg) {
'verb' => ACTIVITY_POST,
'otype' => 'item',
'parent' => $conv_parent,
-
+ 'parent_uri' => $parent_uri
));
// only send one notification
@@ -1560,7 +1674,8 @@ function diaspora_photo($importer,$xml,$msg) {
$link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n";
- $link_text = scale_external_images($link_text);
+ $link_text = scale_external_images($link_text, true,
+ array($remote_photo_name, 'scaled_full_' . $remote_photo_name));
if(strpos($parent_item['body'],$link_text) === false) {
$r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d limit 1",
@@ -1590,8 +1705,8 @@ function diaspora_like($importer,$xml,$msg) {
// likes on comments not supported here and likes on photos not supported by Diaspora
- if($target_type !== 'Post')
- return;
+// if($target_type !== 'Post')
+// return;
$contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']);
if(! $contact) {
@@ -1772,7 +1887,7 @@ EOT;
if(! $parent_author_signature) {
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
intval($message_id),
- dbesc($author_signed_data),
+ dbesc($signed_data),
dbesc(base64_encode($author_signature)),
dbesc($diaspora_handle)
);
@@ -1783,7 +1898,7 @@ EOT;
// is already relaying. The parent_item['origin'] indicates the message was created on our system
if(($parent_item['origin']) && (! $parent_author_signature))
- proc_run('php','include/notifier.php','comment',$message_id);
+ proc_run('php','include/notifier.php','comment-import',$message_id);
return;
}
@@ -1909,7 +2024,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
// is already relaying.
logger('diaspora_signed_retraction: relaying relayable_retraction');
- proc_run('php','include/notifier.php','relayable_retraction',$r[0]['id']);
+ proc_run('php','include/notifier.php','drop',$r[0]['id']);
}
}
}
@@ -1922,11 +2037,17 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
// NOTREACHED
}
-function diaspora_profile($importer,$xml) {
+function diaspora_profile($importer,$xml,$msg) {
$a = get_app();
$diaspora_handle = notags(unxmlify($xml->diaspora_handle));
+
+ if($diaspora_handle != $msg['author']) {
+ logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.');
+ return 202;
+ }
+
$contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
if(! $contact)
return;
@@ -2005,6 +2126,7 @@ function diaspora_share($me,$contact) {
));
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])));
+ //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey']));
return(diaspora_transmit($owner,$contact,$slap, false));
}
@@ -2022,13 +2144,13 @@ function diaspora_unshare($me,$contact) {
));
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])));
+ //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey']));
return(diaspora_transmit($owner,$contact,$slap, false));
}
-
function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
$a = get_app();
@@ -2060,13 +2182,19 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
$images[] = $detail;
$body = str_replace($detail['str'],$mtch[1],$body);
}
- }
+ }
*/
+
+ //if(strlen($title))
+ // $body = "[b]".html_entity_decode($title)."[/b]\n\n".$body;
+
+ // convert to markdown
$body = xmlify(html_entity_decode(bb2diaspora($body)));
+ //$body = bb2diaspora($body);
+ // Adding the title
if(strlen($title))
- $body = xmlify('**' . html_entity_decode($title) . '**' . "\n") . $body;
-
+ $body = "## ".html_entity_decode($title)."\n\n".$body;
if($item['attach']) {
$cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism',$item['attach'],$matches,PREG_SET_ORDER);
@@ -2096,6 +2224,7 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
logger('diaspora_send_status: ' . $owner['username'] . ' -> ' . $contact['name'] . ' base message: ' . $msg, LOGGER_DATA);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
+ //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
$return_code = diaspora_transmit($owner,$contact,$slap,$public_batch);
@@ -2140,6 +2269,7 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals
logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
+ //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
diaspora_transmit($owner,$contact,$slap,$public_batch);
}
@@ -2150,24 +2280,33 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
$a = get_app();
$myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
- $theiraddr = $contact['addr'];
+// $theiraddr = $contact['addr'];
- // The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always
- // return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent.
- // The only item with `parent` and `id` as the parent id is the parent item.
- $p = q("select guid from item where parent = %d and id = %d limit 1",
- intval($item['parent']),
- intval($item['parent'])
- );
+ // Diaspora doesn't support threaded comments
+ /*if($item['thr-parent']) {
+ $p = q("select guid, type, uri, `parent-uri` from item where uri = '%s' limit 1",
+ dbesc($item['thr-parent'])
+ );
+ }
+ else {*/
+ // The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always
+ // return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent.
+ // The only item with `parent` and `id` as the parent id is the parent item.
+ $p = q("select guid, type, uri, `parent-uri` from item where parent = %d and id = %d limit 1",
+ intval($item['parent']),
+ intval($item['parent'])
+ );
+ //}
if(count($p))
- $parent_guid = $p[0]['guid'];
+ $parent = $p[0];
else
return;
if($item['verb'] === ACTIVITY_LIKE) {
$tpl = get_markup_template('diaspora_like.tpl');
$like = true;
- $target_type = 'Post';
+ $target_type = ( $parent['uri'] === $parent['parent-uri'] ? 'Post' : 'Comment');
+// $target_type = (strpos($parent['type'], 'comment') ? 'Comment' : 'Post');
// $positive = (($item['deleted']) ? 'false' : 'true');
$positive = 'true';
@@ -2184,15 +2323,15 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
// sign it
if($like)
- $signed_text = $item['guid'] . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $myaddr;
+ $signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $myaddr;
else
- $signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . ';' . $myaddr;
+ $signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $myaddr;
$authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
$msg = replace_macros($tpl,array(
'$guid' => xmlify($item['guid']),
- '$parent_guid' => xmlify($parent_guid),
+ '$parent_guid' => xmlify($parent['guid']),
'$target_type' =>xmlify($target_type),
'$authorsig' => xmlify($authorsig),
'$body' => xmlify($text),
@@ -2203,6 +2342,7 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
logger('diaspora_followup: base message: ' . $msg, LOGGER_DATA);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
+ //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
}
@@ -2213,18 +2353,28 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
$a = get_app();
$myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
- $theiraddr = $contact['addr'];
+// $theiraddr = $contact['addr'];
+ $body = $item['body'];
+ $text = html_entity_decode(bb2diaspora($body));
- // The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always
- // return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent.
- // The only item with `parent` and `id` as the parent id is the parent item.
- $p = q("select guid from item where parent = %d and id = %d limit 1",
- intval($item['parent']),
- intval($item['parent'])
- );
+ // Diaspora doesn't support threaded comments
+ /*if($item['thr-parent']) {
+ $p = q("select guid, type, uri, `parent-uri` from item where uri = '%s' limit 1",
+ dbesc($item['thr-parent'])
+ );
+ }
+ else {*/
+ // The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always
+ // return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent.
+ // The only item with `parent` and `id` as the parent id is the parent item.
+ $p = q("select guid, type, uri, `parent-uri` from item where parent = %d and id = %d limit 1",
+ intval($item['parent']),
+ intval($item['parent'])
+ );
+ //}
if(count($p))
- $parent_guid = $p[0]['guid'];
+ $parent = $p[0];
else
return;
@@ -2232,31 +2382,31 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
$relay_retract = false;
$sql_sign_id = 'iid';
if( $item['deleted']) {
- $tpl = get_markup_template('diaspora_relayable_retraction.tpl');
$relay_retract = true;
- $sql_sign_id = 'retract_iid';
+
$target_type = ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment');
+
+ $sql_sign_id = 'retract_iid';
+ $tpl = get_markup_template('diaspora_relayable_retraction.tpl');
}
elseif($item['verb'] === ACTIVITY_LIKE) {
- $tpl = get_markup_template('diaspora_like_relay.tpl');
$like = true;
- $target_type = 'Post';
+
+ $target_type = ( $parent['uri'] === $parent['parent-uri'] ? 'Post' : 'Comment');
// $positive = (($item['deleted']) ? 'false' : 'true');
$positive = 'true';
+
+ $tpl = get_markup_template('diaspora_like_relay.tpl');
}
- else {
+ else { // item is a comment
$tpl = get_markup_template('diaspora_comment_relay.tpl');
}
- $body = $item['body'];
-
- $text = html_entity_decode(bb2diaspora($body));
-
// fetch the original signature if the relayable was created by a Diaspora
// or DFRN user. Relayables for other networks are not supported.
- $r = q("select * from sign where " . $sql_sign_id . " = %d limit 1",
+/* $r = q("select * from sign where " . $sql_sign_id . " = %d limit 1",
intval($item['id'])
);
if(count($r)) {
@@ -2272,55 +2422,49 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
// function is called
logger('diaspora_send_relay: original author signature not found, cannot send relayable');
return;
-/*
- $itemcontact = q("select * from contact where `id` = %d limit 1",
- intval($item['contact-id'])
- );
- if(count($itemcontact)) {
- if(! $itemcontact[0]['self']) {
- $prefix = sprintf( t('[Relayed] Comment authored by %s from network %s'),
- '['. $item['author-name'] . ']' . '(' . $item['author-link'] . ')',
- network_to_name($itemcontact['network'])) . "\n";
- // "$body" was assigned to "$text" above. It isn't used after that, so I don't think
- // the following change will do anything
- $body = $prefix . $body;
+ }*/
- // I think this comment will fail upon reaching Diaspora, because "$signed_text" is not defined
- }
- }
- else {
- // I'm confused about this "else." Since it sets "$handle = $myaddr," it seems like it should be for the case
- // where the top-level post owner commented on his own post, i.e. "$itemcontact[0]['self']" is true. But it's
- // positioned to be for the case where "count($itemcontact)" is 0.
+ /* Since the author signature is only checked by the parent, not by the relay recipients,
+ * I think it may not be necessary for us to do so much work to preserve all the original
+ * signatures. The important thing that Diaspora DOES need is the original creator's handle.
+ * Let's just generate that and forget about all the original author signature stuff.
+ *
+ * Note: this might be more of an problem if we want to support likes on comments for older
+ * versions of Diaspora (diaspora-pistos), but since there are a number of problems with
+ * doing that, let's ignore it for now.
+ *
+ * Currently, only DFRN contacts are supported. StatusNet shouldn't be hard, but it hasn't
+ * been done yet
+ */
- $handle = $myaddr;
+ $handle = diaspora_handle_from_contact($item['contact-id']);
+ if(! $handle)
+ return;
- if($like)
- $signed_text = $item['guid'] . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $handle;
- elseif($relay_retract)
- $signed_text = $item['guid'] . ';' . $target_type;
- else
- $signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . ';' . $handle;
- $authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
+ if($relay_retract)
+ $sender_signed_text = $item['guid'] . ';' . $target_type;
+ elseif($like)
+ $sender_signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $handle;
+ else
+ $sender_signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $handle;
- q("insert into sign (`" . $sql_sign_id . "`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
- intval($item['id']),
- dbesc($signed_text),
- dbesc($authorsig),
- dbesc($handle)
- );
- }
-*/
- }
+ // Sign the relayable with the top-level owner's signature
+ //
+ // We'll use the $sender_signed_text that we just created, instead of the $signed_text
+ // stored in the database, because that provides the best chance that Diaspora will
+ // be able to reconstruct the signed text the same way we did. This is particularly a
+ // concern for the comment, whose signed text includes the text of the comment. The
+ // smallest change in the text of the comment, including removing whitespace, will
+ // make the signature verification fail. Since we translate from BB code to Diaspora's
+ // markup at the top of this function, which is AFTER we placed the original $signed_text
+ // in the database, it's hazardous to trust the original $signed_text.
- // sign it with the top-level owner's signature
-
- $parentauthorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
+ $parentauthorsig = base64_encode(rsa_sign($sender_signed_text,$owner['uprvkey'],'sha256'));
$msg = replace_macros($tpl,array(
'$guid' => xmlify($item['guid']),
- '$parent_guid' => xmlify($parent_guid),
+ '$parent_guid' => xmlify($parent['guid']),
'$target_type' =>xmlify($target_type),
'$authorsig' => xmlify($authorsig),
'$parentsig' => xmlify($parentauthorsig),
@@ -2333,6 +2477,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
+ //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
@@ -2367,6 +2512,7 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) {
));
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
+ //$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
}
@@ -2427,13 +2573,14 @@ function diaspora_send_mail($item,$owner,$contact) {
logger('diaspora_conversation: ' . print_r($xmsg,true), LOGGER_DATA);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false)));
+ //$slap = 'xml=' . urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false));
return(diaspora_transmit($owner,$contact,$slap,false));
}
-function diaspora_transmit($owner,$contact,$slap,$public_batch) {
+function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false) {
$enabled = intval(get_config('system','diaspora_enabled'));
if(! $enabled) {
@@ -2450,7 +2597,7 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch) {
logger('diaspora_transmit: ' . $logid . ' ' . $dest_url);
- if(was_recently_delayed($contact['id'])) {
+ if( (! $queue_run) && (was_recently_delayed($contact['id'])) ) {
$return_code = 0;
}
else {
diff --git a/include/enotify.php b/include/enotify.php
index 134e42f8e..b4331f092 100644
--- a/include/enotify.php
+++ b/include/enotify.php
@@ -1,5 +1,7 @@
' . $sitename . '');
+ $itemlink = $params['link'];
+ }
+
if($params['type'] == NOTIFY_TAGSHARE) {
$subject = sprintf( t('[Friendica:Notify] %s tagged your post') , $params['source_name']);
$preamble = sprintf( t('%1$s tagged your post at %2$s') , $params['source_name'], $sitename);
@@ -292,7 +326,7 @@ function notification($params) {
// If so, create the record of it and use a message-id smtp header.
if(!$r) {
- logger("norify_id:" . intval($notify_id). ", parent: " . intval($params['parent']) . "uid: " .
+ logger("notify_id:" . intval($notify_id). ", parent: " . intval($params['parent']) . "uid: " .
intval($params['uid']), LOGGER_DEBUG);
$r = q("insert into `notify-threads` (`notify-id`, `master-parent-item`, `receiver-uid`, `parent-item`)
values(%d,%d,%d,%d)",
@@ -463,6 +497,7 @@ class enotify {
$multipartMessageBody, // message body
$messageHeader // message headers
);
+ logger("notification: enotify::send header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
logger("notification: enotify::send returns " . $res, LOGGER_DEBUG);
}
}
diff --git a/include/event.php b/include/event.php
index 866ae8c3f..8aef0a263 100644
--- a/include/event.php
+++ b/include/event.php
@@ -12,6 +12,9 @@ function format_event_html($ev) {
$o = '
' . "\r\n";
+
+ $o .= '
' . bbcode($ev['summary']) . '
' . "\r\n";
+
$o .= '
' . bbcode($ev['desc']) . '
' . "\r\n";
$o .= '
' . t('Starts:') . ' nodeValue = str_replace("\n", "\r", $node->nodeValue);
$message = $doc->saveHTML();
- $message = str_replace(array("\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"), array("<", ">", " ", " ", ""), $message);
+ $message = str_replace(array("\n<", ">\n", "\r", "\n", "\xC3\x82\xC2\xA0"), array("<", ">", " ", " ", ""), $message);
$message = preg_replace('= [\s]*=i', " ", $message);
@$doc->loadHTML($message);
diff --git a/include/items.php b/include/items.php
index 05134ef8f..f70e96fcb 100755
--- a/include/items.php
+++ b/include/items.php
@@ -4,6 +4,8 @@ require_once('include/bbcode.php');
require_once('include/oembed.php');
require_once('include/salmon.php');
require_once('include/crypto.php');
+require_once('include/Photo.php');
+
function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
@@ -278,8 +280,123 @@ function construct_activity_target($item) {
}
return '';
-}
+}
+/* limit_body_size()
+ *
+ * The purpose of this function is to apply system message length limits to
+ * imported messages without including any embedded photos in the length
+ */
+if(! function_exists('limit_body_size')) {
+function limit_body_size($body) {
+
+ logger('limit_body_size: start', LOGGER_DEBUG);
+
+ $maxlen = get_max_import_size();
+
+ // If the length of the body, including the embedded images, is smaller
+ // than the maximum, then don't waste time looking for the images
+ if($maxlen && (strlen($body) > $maxlen)) {
+
+ logger('limit_body_size: the total body length exceeds the limit', LOGGER_DEBUG);
+
+ $orig_body = $body;
+ $new_body = '';
+ $textlen = 0;
+ $max_found = false;
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ while(($img_st_close !== false) && ($img_end !== false)) {
+
+ $img_st_close++; // make it point to AFTER the closing bracket
+ $img_end += $img_start;
+ $img_end += strlen('[/img]');
+
+ if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
+ // This is an embedded image
+
+ if( ($textlen + $img_start) > $maxlen ) {
+ if($textlen < $maxlen) {
+ logger('limit_body_size: the limit happens before an embedded image', LOGGER_DEBUG);
+ $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
+ $textlen = $maxlen;
+ }
+ }
+ else {
+ $new_body = $new_body . substr($orig_body, 0, $img_start);
+ $textlen += $img_start;
+ }
+
+ $new_body = $new_body . substr($orig_body, $img_start, $img_end - $img_start);
+ }
+ else {
+
+ if( ($textlen + $img_end) > $maxlen ) {
+ if($textlen < $maxlen) {
+ logger('limit_body_size: the limit happens before the end of a non-embedded image', LOGGER_DEBUG);
+ $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
+ $textlen = $maxlen;
+ }
+ }
+ else {
+ $new_body = $new_body . substr($orig_body, 0, $img_end);
+ $textlen += $img_end;
+ }
+ }
+ $orig_body = substr($orig_body, $img_end);
+
+ if($orig_body === false) // in case the body ends on a closing image tag
+ $orig_body = '';
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+ }
+
+ if( ($textlen + strlen($orig_body)) > $maxlen) {
+ if($textlen < $maxlen) {
+ logger('limit_body_size: the limit happens after the end of the last image', LOGGER_DEBUG);
+ $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
+ $textlen = $maxlen;
+ }
+ }
+ else {
+ logger('limit_body_size: the text size with embedded images extracted did not violate the limit', LOGGER_DEBUG);
+ $new_body = $new_body . $orig_body;
+ $textlen += strlen($orig_body);
+ }
+
+ return $new_body;
+ }
+ else
+ return $body;
+}}
+
+function title_is_body($title, $body) {
+
+ $title = strip_tags($title);
+ $title = trim($title);
+ $title = str_replace(array("\n", "\r", "\t", " "), array("","","",""), $title);
+
+ $body = strip_tags($body);
+ $body = trim($body);
+ $body = str_replace(array("\n", "\r", "\t", " "), array("","","",""), $body);
+
+ if (strlen($title) < strlen($body))
+ $body = substr($body, 0, strlen($title));
+
+ if (($title != $body) and (substr($title, -3) == "...")) {
+ $pos = strrpos($title, "...");
+ if ($pos > 0) {
+ $title = substr($title, 0, $pos);
+ $body = substr($body, 0, $pos);
+ }
+ }
+
+ return($title == $body);
+}
@@ -306,6 +423,11 @@ function get_atom_elements($feed,$item) {
$res['body'] = unxmlify($item->get_content());
$res['plink'] = unxmlify($item->get_link(0));
+ // removing the content of the title if its identically to the body
+ // This helps with auto generated titles e.g. from tumblr
+ if (title_is_body($res["title"], $res["body"]))
+ $res['title'] = "";
+
if($res['plink'])
$base_url = implode('/', array_slice(explode('/',$res['plink']),0,3));
else
@@ -324,7 +446,7 @@ function get_atom_elements($feed,$item) {
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
- }
+ }
$rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor');
@@ -356,7 +478,7 @@ function get_atom_elements($feed,$item) {
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
- }
+ }
$rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject');
@@ -381,7 +503,7 @@ function get_atom_elements($feed,$item) {
$res['app'] = strip_tags(unxmlify($apps[0]['attribs']['']['source']));
if($res['app'] === 'web')
$res['app'] = 'OStatus';
- }
+ }
// base64 encoded json structure representing Diaspora signature
@@ -414,9 +536,8 @@ function get_atom_elements($feed,$item) {
$res['body'] = notags(base64url_decode($res['body']));
}
- $maxlen = get_max_import_size();
- if($maxlen && (strlen($res['body']) > $maxlen))
- $res['body'] = substr($res['body'],0, $maxlen);
+
+ $res['body'] = limit_body_size($res['body']);
// It isn't certain at this point whether our content is plaintext or html and we'd be foolish to trust
// the content type. Our own network only emits text normally, though it might have been converted to
@@ -446,6 +567,8 @@ function get_atom_elements($feed,$item) {
$res['body'] = $purifier->purify($res['body']);
$res['body'] = @html2bbcode($res['body']);
+
+
}
elseif(! $have_real_body) {
@@ -455,6 +578,7 @@ function get_atom_elements($feed,$item) {
$res['body'] = escape_tags($res['body']);
}
+
// this tag is obsolete but we keep it for really old sites
$allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
@@ -464,8 +588,8 @@ function get_atom_elements($feed,$item) {
$res['last-child'] = 0;
$private = $item->get_item_tags(NAMESPACE_DFRN,'private');
- if($private && $private[0]['data'] == 1)
- $res['private'] = 1;
+ if($private && intval($private[0]['data']) > 0)
+ $res['private'] = intval($private[0]['data']);
else
$res['private'] = 0;
@@ -523,7 +647,7 @@ function get_atom_elements($feed,$item) {
foreach($base as $link) {
if(!x($res, 'owner-avatar') || !$res['owner-avatar']) {
- if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
+ if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
$res['owner-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
@@ -663,10 +787,41 @@ function get_atom_elements($feed,$item) {
$res['target'] .= '' . "\n";
}
+ // This is some experimental stuff. By now retweets are shown with "RT:"
+ // But: There is data so that the message could be shown similar to native retweets
+ // There is some better way to parse this array - but it didn't worked for me.
+ $child = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://activitystrea.ms/spec/1.0/"][object][0]["child"];
+ if (is_array($child)) {
+ $message = $child["http://activitystrea.ms/spec/1.0/"]["object"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["content"][0]["data"];
+ $author = $child[SIMPLEPIE_NAMESPACE_ATOM_10]["author"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10];
+ $uri = $author["uri"][0]["data"];
+ $name = $author["name"][0]["data"];
+ $avatar = @array_shift($author["link"][2]["attribs"]);
+ $avatar = $avatar["href"];
+
+ if (($name != "") and ($uri != "") and ($avatar != "") and ($message != "")) {
+ $res["owner-name"] = $res["author-name"];
+ $res["owner-link"] = $res["author-link"];
+ $res["owner-avatar"] = $res["author-avatar"];
+
+ $res["author-name"] = $name;
+ $res["author-link"] = $uri;
+ $res["author-avatar"] = $avatar;
+
+ $res["body"] = html2bbcode($message);
+ }
+ }
+
$arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
call_hooks('parse_atom', $arr);
+ //if (($res["title"] != "") or (strpos($res["body"], "RT @") > 0)) {
+ //if (strpos($res["body"], "RT @") !== false) {
+ // $debugfile = tempnam("/home/ike/log", "item-res2-");
+ // file_put_contents($debugfile, serialize($arr));
+ //}
+
return $res;
}
@@ -722,6 +877,14 @@ function item_store($arr,$force_parent = false) {
$arr['body'] = strip_tags($arr['body']);
+ if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
+ require_once('Text/LanguageDetect.php');
+ $naked_body = preg_replace('/\[(.+?)\]/','',$arr['body']);
+ $l = new Text_LanguageDetect;
+ $lng = $l->detectConfidence($naked_body);
+ $arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
+ }
+
$arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
$arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string());
$arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : '');
@@ -762,6 +925,8 @@ function item_store($arr,$force_parent = false) {
$arr['origin'] = ((x($arr,'origin')) ? intval($arr['origin']) : 0 );
$arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid());
+
+ $arr['thr-parent'] = $arr['parent-uri'];
if($arr['parent-uri'] === $arr['uri']) {
$parent_id = 0;
$parent_deleted = 0;
@@ -787,9 +952,8 @@ function item_store($arr,$force_parent = false) {
// and re-attach to the conversation parent.
if($r[0]['uri'] != $r[0]['parent-uri']) {
- $arr['thr-parent'] = $arr['parent-uri'];
$arr['parent-uri'] = $r[0]['parent-uri'];
- $z = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d
+ $z = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d
ORDER BY `id` ASC LIMIT 1",
dbesc($r[0]['parent-uri']),
dbesc($r[0]['parent-uri']),
@@ -812,7 +976,7 @@ function item_store($arr,$force_parent = false) {
// email correspondents to be private even if the overall thread is not.
if($r[0]['private'])
- $arr['private'] = 1;
+ $arr['private'] = $r[0]['private'];
// Edge case. We host a public forum that was originally posted to privately.
// The original author commented, but as this is a comment, the permissions
@@ -829,7 +993,6 @@ function item_store($arr,$force_parent = false) {
if($force_parent) {
logger('item_store: $force_parent=true, reply converted to top-level post.');
$parent_id = 0;
- $arr['thr-parent'] = $arr['parent-uri'];
$arr['parent-uri'] = $arr['uri'];
$arr['gravity'] = 0;
}
@@ -1021,6 +1184,15 @@ function tag_deliver($uid,$item_id) {
// send a notification
+ // use a local photo if we have one
+
+ $r = q("select thumb from contact where uid = %d and nurl = '%s' limit 1",
+ intval($u[0]['uid']),
+ dbesc(normalise_link($item['author-link']))
+ );
+ $photo = (($r && count($r)) ? $r[0]['thumb'] : $item['author-avatar']);
+
+
require_once('include/enotify.php');
notification(array(
'type' => NOTIFY_TAGSELF,
@@ -1033,7 +1205,7 @@ function tag_deliver($uid,$item_id) {
'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item['id'],
'source_name' => $item['author-name'],
'source_link' => $item['author-link'],
- 'source_photo' => $item['author-avatar'],
+ 'source_photo' => $photo,
'verb' => ACTIVITY_TAG,
'otype' => 'item'
));
@@ -1084,6 +1256,59 @@ function tag_deliver($uid,$item_id) {
+function tgroup_check($uid,$item) {
+
+ $a = get_app();
+
+ $mention = false;
+
+ // check that the message originated elsewhere and is a top-level post
+
+ if(($item['wall']) || ($item['origin']) || ($item['uri'] != $item['parent-uri']))
+ return false;
+
+
+ $u = q("select * from user where uid = %d limit 1",
+ intval($uid)
+ );
+ if(! count($u))
+ return false;
+
+ $community_page = (($u[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
+ $prvgroup = (($u[0]['page-flags'] == PAGE_PRVGROUP) ? true : false);
+
+
+ $link = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']);
+
+ // Diaspora uses their own hardwired link URL in @-tags
+ // instead of the one we supply with webfinger
+
+ $dlink = normalise_link($a->get_baseurl() . '/u/' . $u[0]['nickname']);
+
+ $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism',$item['body'],$matches,PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ if(link_compare($link,$mtch[1]) || link_compare($dlink,$mtch[1])) {
+ $mention = true;
+ logger('tgroup_check: mention found: ' . $mtch[2]);
+ }
+ }
+ }
+
+ if(! $mention)
+ return false;
+
+ if((! $community_page) && (! $prvgroup))
+ return false;
+
+
+
+ return true;
+
+}
+
+
+
@@ -1264,6 +1489,12 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
return 3;
}
+ if($contact['term-date'] != '0000-00-00 00:00:00') {
+ logger("dfrn_deliver: $url back from the dead - removing mark for death");
+ require_once('include/Contact.php');
+ unmark_for_death($contact);
+ }
+
$res = parse_xml_string($xml);
return $res->status;
@@ -1449,11 +1680,12 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
*
*/
- $bdtext = t('Birthday:') . ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' ;
+ $bdtext = sprintf( t('%s\'s birthday'), $contact['name']);
+ $bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' ) ;
- $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`desc`,`type`)
- VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s' ) ",
+ $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`)
+ VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($contact['uid']),
intval($contact['id']),
dbesc(datetime_convert()),
@@ -1461,6 +1693,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
dbesc(datetime_convert('UTC','UTC', $birthday)),
dbesc(datetime_convert('UTC','UTC', $birthday . ' + 1 day ')),
dbesc($bdtext),
+ dbesc($bdtext2),
dbesc('birthday')
);
@@ -1606,7 +1839,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
// Now process the feed
- if($feed->get_item_quantity()) {
+ if($feed->get_item_quantity()) {
logger('consume_feed: feed item count = ' . $feed->get_item_quantity());
@@ -1619,7 +1852,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
foreach($items as $item) {
- $is_reply = false;
+ $is_reply = false;
$item_id = $item->get_id();
$rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to');
if(isset($rawthread[0]['attribs']['']['ref'])) {
@@ -1632,12 +1865,17 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
if($pass == 1)
continue;
+ // not allowed to post
+
+ if($contact['rel'] == CONTACT_IS_FOLLOWER)
+ continue;
+
+
// Have we seen it? If not, import it.
-
+
$item_id = $item->get_id();
$datarray = get_atom_elements($feed,$item);
-
if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN))
$datarray['author-name'] = $contact['name'];
if((! x($datarray,'author-link')) && ($contact['network'] != NETWORK_DFRN))
@@ -1650,6 +1888,21 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
continue;
}
+ $force_parent = false;
+ if($contact['network'] === NETWORK_OSTATUS || stristr($contact['url'],'twitter.com')) {
+ if($contact['network'] === NETWORK_OSTATUS)
+ $force_parent = true;
+ if(strlen($datarray['title']))
+ unset($datarray['title']);
+ $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
+ dbesc(datetime_convert()),
+ dbesc($parent_uri),
+ intval($importer['uid'])
+ );
+ $datarray['last-child'] = 1;
+ }
+
+
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['uid'])
@@ -1693,19 +1946,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
continue;
}
- $force_parent = false;
- if($contact['network'] === NETWORK_OSTATUS || stristr($contact['url'],'twitter.com')) {
- if($contact['network'] === NETWORK_OSTATUS)
- $force_parent = true;
- if(strlen($datarray['title']))
- unset($datarray['title']);
- $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
- dbesc(datetime_convert()),
- dbesc($parent_uri),
- intval($importer['uid'])
- );
- $datarray['last-child'] = 1;
- }
if(($contact['network'] === NETWORK_FEED) || (! strlen($contact['notify']))) {
// one way feed - no remote comment ability
@@ -1718,10 +1958,12 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
// only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr-parent` = '%s') limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
- dbesc($datarray['verb'])
+ dbesc($datarray['verb']),
+ dbesc($parent_uri),
+ dbesc($parent_uri)
);
if($r && count($r))
continue;
@@ -1801,6 +2043,13 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
}
}
+ if($contact['network'] === NETWORK_OSTATUS || stristr($contact['url'],'twitter.com')) {
+ if(strlen($datarray['title']))
+ unset($datarray['title']);
+ $datarray['last-child'] = 1;
+ }
+
+
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['uid'])
@@ -1863,24 +2112,23 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
if(! is_array($contact))
return;
- if($contact['network'] === NETWORK_OSTATUS || stristr($contact['url'],'twitter.com')) {
- if(strlen($datarray['title']))
- unset($datarray['title']);
- $datarray['last-child'] = 1;
- }
if(($contact['network'] === NETWORK_FEED) || (! strlen($contact['notify']))) {
// one way feed - no remote comment ability
$datarray['last-child'] = 0;
}
if($contact['network'] === NETWORK_FEED)
- $datarray['private'] = 1;
+ $datarray['private'] = 2;
// This is my contact on another system, but it's really me.
// Turn this into a wall post.
- if($contact['remote_self'])
+ if($contact['remote_self']) {
$datarray['wall'] = 1;
+ if($contact['network'] === NETWORK_FEED) {
+ $datarray['private'] = 0;
+ }
+ }
$datarray['parent-uri'] = $item_id;
$datarray['uid'] = $importer['uid'];
@@ -1897,6 +2145,14 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$datarray['owner-avatar'] = $contact['thumb'];
}
+ // We've allowed "followers" to reach this point so we can decide if they are
+ // posting an @-tag delivery, which followers are allowed to do for certain
+ // page types. Now that we've parsed the post, let's check if it is legit. Otherwise ignore it.
+
+ if(($contact['rel'] == CONTACT_IS_FOLLOWER) && (! tgroup_check($importer['uid'],$datarray)))
+ continue;
+
+
$r = item_store($datarray);
continue;
@@ -1928,6 +2184,121 @@ function local_delivery($importer,$data) {
$feed->enable_order_by_date(false);
$feed->init();
+
+ if($feed->error())
+ logger('local_delivery: Error parsing XML: ' . $feed->error());
+
+
+ // Check at the feed level for updated contact name and/or photo
+
+ $name_updated = '';
+ $new_name = '';
+ $photo_timestamp = '';
+ $photo_url = '';
+
+
+ $rawtags = $feed->get_feed_tags( NAMESPACE_DFRN, 'owner');
+
+// Fallback should not be needed here. If it isn't DFRN it won't have DFRN updated tags
+// if(! $rawtags)
+// $rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
+
+ if($rawtags) {
+ $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
+ if($elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated']) {
+ $name_updated = $elems['name'][0]['attribs'][NAMESPACE_DFRN]['updated'];
+ $new_name = $elems['name'][0]['data'];
+ }
+ if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo') && ($elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated'])) {
+ $photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']);
+ $photo_url = $elems['link'][0]['attribs']['']['href'];
+ }
+ }
+
+ if(($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $importer['avatar-date'])) {
+ logger('local_delivery: Updating photo for ' . $importer['name']);
+ require_once("Photo.php");
+ $photo_failure = false;
+ $have_photo = false;
+
+ $r = q("SELECT `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d LIMIT 1",
+ intval($importer['id']),
+ intval($importer['importer_uid'])
+ );
+ if(count($r)) {
+ $resource_id = $r[0]['resource-id'];
+ $have_photo = true;
+ }
+ else {
+ $resource_id = photo_new_resource();
+ }
+
+ $img_str = fetch_url($photo_url,true);
+ // guess mimetype from headers or filename
+ $type = guess_image_type($photo_url,true);
+
+
+ $img = new Photo($img_str, $type);
+ if($img->is_valid()) {
+ if($have_photo) {
+ q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `contact-id` = %d AND `uid` = %d",
+ dbesc($resource_id),
+ intval($importer['id']),
+ intval($importer['importer_uid'])
+ );
+ }
+
+ $img->scaleImageSquare(175);
+
+ $hash = $resource_id;
+ $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 4);
+
+ $img->scaleImage(80);
+ $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 5);
+
+ $img->scaleImage(48);
+ $r = $img->store($importer['importer_uid'], $importer['id'], $hash, basename($photo_url), 'Contact Photos', 6);
+
+ $a = get_app();
+
+ q("UPDATE `contact` SET `avatar-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s'
+ WHERE `uid` = %d AND `id` = %d LIMIT 1",
+ dbesc(datetime_convert()),
+ dbesc($a->get_baseurl() . '/photo/' . $hash . '-4.'.$img->getExt()),
+ dbesc($a->get_baseurl() . '/photo/' . $hash . '-5.'.$img->getExt()),
+ dbesc($a->get_baseurl() . '/photo/' . $hash . '-6.'.$img->getExt()),
+ intval($importer['importer_uid']),
+ intval($importer['id'])
+ );
+ }
+ }
+
+ if(($name_updated) && (strlen($new_name)) && ($name_updated > $importer['name-date'])) {
+ $r = q("select * from contact where uid = %d and id = %d limit 1",
+ intval($importer['importer_uid']),
+ intval($importer['id'])
+ );
+
+ $x = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
+ dbesc(notags(trim($new_name))),
+ dbesc(datetime_convert()),
+ intval($importer['importer_uid']),
+ intval($importer['id'])
+ );
+
+ // do our best to update the name on content items
+
+ if(count($r)) {
+ q("update item set `author-name` = '%s' where `author-name` = '%s' and `author-link` = '%s' and uid = %d",
+ dbesc(notags(trim($new_name))),
+ dbesc($r[0]['name']),
+ dbesc($r[0]['url']),
+ intval($importer['importer_uid'])
+ );
+ }
+ }
+
+
/*
// Currently unsupported - needs a lot of work
$reloc = $feed->get_feed_tags( NAMESPACE_DFRN, 'relocate' );
@@ -2138,6 +2509,68 @@ function local_delivery($importer,$data) {
}
if($deleted) {
+ // check for relayed deletes to our conversation
+
+ $is_reply = false;
+ $r = q("select * from item where uri = '%s' and uid = %d limit 1",
+ dbesc($uri),
+ intval($importer['importer_uid'])
+ );
+ if(count($r)) {
+ $parent_uri = $r[0]['parent-uri'];
+ if($r[0]['id'] != $r[0]['parent'])
+ $is_reply = true;
+ }
+
+ if($is_reply) {
+ $community = false;
+
+ if($importer['page-flags'] == PAGE_COMMUNITY || $importer['page-flags'] == PAGE_PRVGROUP ) {
+ $sql_extra = '';
+ $community = true;
+ logger('local_delivery: possible community delete');
+ }
+ else
+ $sql_extra = " and contact.self = 1 and item.wall = 1 ";
+
+ // was the top-level post for this reply written by somebody on this site?
+ // Specifically, the recipient?
+
+ $is_a_remote_delete = false;
+
+ // POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used?
+ $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`,
+ `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
+ LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
+ WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s')
+ AND `item`.`uid` = %d
+ $sql_extra
+ LIMIT 1",
+ dbesc($parent_uri),
+ dbesc($parent_uri),
+ dbesc($parent_uri),
+ intval($importer['importer_uid'])
+ );
+ if($r && count($r))
+ $is_a_remote_delete = true;
+
+ // Does this have the characteristics of a community or private group comment?
+ // If it's a reply to a wall post on a community/prvgroup page it's a
+ // valid community comment. Also forum_mode makes it valid for sure.
+ // If neither, it's not.
+
+ if($is_a_remote_delete && $community) {
+ if((! $r[0]['forum_mode']) && (! $r[0]['wall'])) {
+ $is_a_remote_delete = false;
+ logger('local_delivery: not a community delete');
+ }
+ }
+
+ if($is_a_remote_delete) {
+ logger('local_delivery: received remote delete');
+ }
+ }
+
$r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join contact on `item`.`contact-id` = `contact`.`id`
WHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1",
dbesc($uri),
@@ -2190,7 +2623,8 @@ function local_delivery($importer,$data) {
}
if($item['uri'] == $item['parent-uri']) {
- $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'
+ $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
+ `body` = '', `title` = ''
WHERE `parent-uri` = '%s' AND `uid` = %d",
dbesc($when),
dbesc(datetime_convert()),
@@ -2199,7 +2633,8 @@ function local_delivery($importer,$data) {
);
}
else {
- $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'
+ $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
+ `body` = '', `title` = ''
WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($when),
dbesc(datetime_convert()),
@@ -2225,7 +2660,11 @@ function local_delivery($importer,$data) {
);
}
}
- }
+ // if this is a relayed delete, propagate it to other recipients
+
+ if($is_a_remote_delete)
+ proc_run('php',"include/notifier.php","drop",$item['id']);
+ }
}
}
}
@@ -2257,20 +2696,32 @@ function local_delivery($importer,$data) {
// Specifically, the recipient?
$is_a_remote_comment = false;
-
- $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`,
- `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
- LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
- WHERE `item`.`uri` = '%s' AND `item`.`parent-uri` = '%s'
- AND `item`.`uid` = %d
- $sql_extra
+ $top_uri = $parent_uri;
+
+ $r = q("select `item`.`parent-uri` from `item`
+ WHERE `item`.`uri` = '%s'
LIMIT 1",
- dbesc($parent_uri),
- dbesc($parent_uri),
- intval($importer['importer_uid'])
+ dbesc($parent_uri)
);
- if($r && count($r))
- $is_a_remote_comment = true;
+ if($r && count($r)) {
+ $top_uri = $r[0]['parent-uri'];
+
+ // POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used?
+ $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`,
+ `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
+ LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
+ WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s')
+ AND `item`.`uid` = %d
+ $sql_extra
+ LIMIT 1",
+ dbesc($top_uri),
+ dbesc($top_uri),
+ dbesc($top_uri),
+ intval($importer['importer_uid'])
+ );
+ if($r && count($r))
+ $is_a_remote_comment = true;
+ }
// Does this have the characteristics of a community or private group comment?
// If it's a reply to a wall post on a community/prvgroup page it's a
@@ -2324,15 +2775,6 @@ function local_delivery($importer,$data) {
}
- // TODO: make this next part work against both delivery threads of a community post
-
-// if((! link_compare($datarray['author-link'],$importer['url'])) && (! $community)) {
-// logger('local_delivery: received relay claiming to be from ' . $importer['url'] . ' however comment author url is ' . $datarray['author-link'] );
- // they won't know what to do so don't report an error. Just quietly die.
-// return 0;
-// }
-
- // our user with $importer['importer_uid'] is the owner
$own = q("select name,url,thumb from contact where uid = %d and self = 1 limit 1",
intval($importer['importer_uid'])
@@ -2354,10 +2796,13 @@ function local_delivery($importer,$data) {
$datarray['gravity'] = GRAVITY_LIKE;
$datarray['last-child'] = 0;
// only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr-parent` = '%s' or `parent-uri` = '%s') and deleted = 0 limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
- dbesc($datarray['verb'])
+ dbesc($datarray['verb']),
+ dbesc($datarray['parent-uri']),
+ dbesc($datarray['parent-uri'])
+
);
if($r && count($r))
continue;
@@ -2399,26 +2844,19 @@ function local_delivery($importer,$data) {
}
}
-// if($community) {
-// $newtag = '@[url=' . $a->get_baseurl() . '/profile/' . $importer['nickname'] . ']' . $importer['username'] . '[/url]';
-// if(! stristr($datarray['tag'],$newtag)) {
-// if(strlen($datarray['tag']))
-// $datarray['tag'] .= ',';
-// $datarray['tag'] .= $newtag;
-// }
-// }
-
$posted_id = item_store($datarray);
$parent = 0;
if($posted_id) {
- $r = q("SELECT `parent` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `parent`, `parent-uri` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($posted_id),
intval($importer['importer_uid'])
);
- if(count($r))
+ if(count($r)) {
$parent = $r[0]['parent'];
+ $parent_uri = $r[0]['parent-uri'];
+ }
if(! $is_like) {
$r1 = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d",
@@ -2435,7 +2873,7 @@ function local_delivery($importer,$data) {
}
if($posted_id && $parent) {
-
+
proc_run('php',"include/notifier.php","comment-import","$posted_id");
if((! $is_like) && (! $importer['self'])) {
@@ -2458,7 +2896,7 @@ function local_delivery($importer,$data) {
'verb' => ACTIVITY_POST,
'otype' => 'item',
'parent' => $parent,
-
+ 'parent_uri' => $parent_uri,
));
}
@@ -2475,6 +2913,9 @@ function local_delivery($importer,$data) {
$item_id = $item->get_id();
$datarray = get_atom_elements($feed,$item);
+ if($importer['rel'] == CONTACT_IS_FOLLOWER)
+ continue;
+
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['importer_uid'])
@@ -2525,10 +2966,12 @@ function local_delivery($importer,$data) {
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
// only one like or dislike per person
- $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 limit 1",
+ $r = q("select id from item where uid = %d and `contact-id` = %d and verb ='%s' and deleted = 0 and (`parent-uri` = '%s' OR `thr-parent` = '%s') limit 1",
intval($datarray['uid']),
intval($datarray['contact-id']),
- dbesc($datarray['verb'])
+ dbesc($datarray['verb']),
+ dbesc($parent_uri),
+ dbesc($parent_uri)
);
if($r && count($r))
continue;
@@ -2567,7 +3010,7 @@ function local_delivery($importer,$data) {
if(!x($datarray['type']) || $datarray['type'] != 'activity') {
$myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0",
- dbesc($parent_uri),
+ dbesc($top_uri),
intval($importer['importer_uid'])
);
@@ -2605,6 +3048,7 @@ function local_delivery($importer,$data) {
'verb' => ACTIVITY_POST,
'otype' => 'item',
'parent' => $conv_parent,
+ 'parent_uri' => $parent_uri
));
@@ -2694,7 +3138,8 @@ function local_delivery($importer,$data) {
$datarray['uid'] = $importer['importer_uid'];
$datarray['contact-id'] = $importer['id'];
- if(! link_compare($datarray['owner-link'],$contact['url'])) {
+
+ if(! link_compare($datarray['owner-link'],$importer['url'])) {
// The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery,
// but otherwise there's a possible data mixup on the sender's system.
// the tgroup delivery code called from item_store will correct it if it's a forum,
@@ -2705,7 +3150,60 @@ function local_delivery($importer,$data) {
$datarray['owner-avatar'] = $importer['thumb'];
}
- $r = item_store($datarray);
+ if(($importer['rel'] == CONTACT_IS_FOLLOWER) && (! tgroup_check($importer['importer_uid'],$datarray)))
+ continue;
+
+ $posted_id = item_store($datarray);
+
+ if(stristr($datarray['verb'],ACTIVITY_POKE)) {
+ $verb = urldecode(substr($datarray['verb'],strpos($datarray['verb'],'#')+1));
+ if(! $verb)
+ continue;
+ $xo = parse_xml_string($datarray['object'],false);
+
+ if(($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) {
+
+ // somebody was poked/prodded. Was it me?
+
+ $links = parse_xml_string("".unxmlify($xo->link)."",false);
+
+ foreach($links->link as $l) {
+ $atts = $l->attributes();
+ switch($atts['rel']) {
+ case "alternate":
+ $Blink = $atts['href'];
+ break;
+ default:
+ break;
+ }
+ }
+ if($Blink && link_compare($Blink,$a->get_baseurl() . '/profile/' . $importer['nickname'])) {
+
+ // send a notification
+ require_once('include/enotify.php');
+
+ notification(array(
+ 'type' => NOTIFY_POKE,
+ 'notify_flags' => $importer['notify-flags'],
+ 'language' => $importer['language'],
+ 'to_name' => $importer['username'],
+ 'to_email' => $importer['email'],
+ 'uid' => $importer['importer_uid'],
+ 'item' => $datarray,
+ 'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
+ 'source_name' => stripslashes($datarray['author-name']),
+ 'source_link' => $datarray['author-link'],
+ 'source_photo' => ((link_compare($datarray['author-link'],$importer['url']))
+ ? $importer['thumb'] : $datarray['author-avatar']),
+ 'verb' => $datarray['verb'],
+ 'otype' => 'person',
+ 'activity' => $verb,
+
+ ));
+ }
+ }
+ }
+
continue;
}
}
@@ -2913,7 +3411,6 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
else
$body = $item['body'];
-
$o = "\r\n\r\n\r\n";
if(is_array($author))
@@ -2923,8 +3420,10 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
if(strlen($item['owner-name']))
$o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']);
- if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']))
- $o .= '' . "\r\n";
+ if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
+ $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
+ $o .= '' . "\r\n";
+ }
$o .= '' . xmlify($item['uri']) . '' . "\r\n";
$o .= '' . xmlify($item['title']) . '' . "\r\n";
@@ -2945,7 +3444,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
$o .= '' . xmlify($item['coord']) . '' . "\r\n";
if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid']))
- $o .= '1' . "\r\n";
+ $o .= '' . (($item['private']) ? $item['private'] : 1) . '' . "\r\n";
if($item['extid'])
$o .= '' . xmlify($item['extid']) . '' . "\r\n";
@@ -2992,20 +3491,33 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
return $o;
}
-function fix_private_photos($s,$uid, $item = null, $cid = 0) {
+function fix_private_photos($s, $uid, $item = null, $cid = 0) {
$a = get_app();
logger('fix_private_photos', LOGGER_DEBUG);
$site = substr($a->get_baseurl(),strpos($a->get_baseurl(),'://'));
- if(preg_match("/\[img(.*?)\](.*?)\[\/img\]/is",$s,$matches)) {
- $image = $matches[2];
+ $orig_body = $s;
+ $new_body = '';
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
+ while( ($img_st_close !== false) && ($img_len !== false) ) {
+
+ $img_st_close++; // make it point to AFTER the closing bracket
+ $image = substr($orig_body, $img_start + $img_st_close, $img_len);
+
logger('fix_private_photos: found photo ' . $image, LOGGER_DEBUG);
+
+
if(stristr($image , $site . '/photo/')) {
+ // Only embed locally hosted photos
$replace = false;
$i = basename($image);
$i = str_replace(array('.jpg','.png'),array('',''),$i);
$x = strpos($i,'-');
+
if($x) {
$res = substr($i,$x+1);
$i = substr($i,0,$x);
@@ -3023,14 +3535,6 @@ function fix_private_photos($s,$uid, $item = null, $cid = 0) {
// 3. Otherwise, if we have an item, see if the item permissions match the photo
// permissions, regardless of order but first check to see if they're an exact
// match to save some processing overhead.
-
- // Currently we only embed one private photo per message so as not to hit import
- // size limits at the receiving end.
-
- // To embed multiples, we would need to parse out the embedded photos on message
- // receipt and limit size based only on the text component. Would also need to
- // ignore all photos during bbcode translation and item localisation, as these
- // will hit internal regex backtrace limits.
if(has_permissions($r[0])) {
if($cid) {
@@ -3045,15 +3549,45 @@ function fix_private_photos($s,$uid, $item = null, $cid = 0) {
}
}
if($replace) {
+ $data = $r[0]['data'];
+ $type = $r[0]['type'];
+
+ // If a custom width and height were specified, apply before embedding
+ if(preg_match("/\[img\=([0-9]*)x([0-9]*)\]/is", substr($orig_body, $img_start, $img_st_close), $match)) {
+ logger('fix_private_photos: scaling photo', LOGGER_DEBUG);
+
+ $width = intval($match[1]);
+ $height = intval($match[2]);
+
+ $ph = new Photo($data, $type);
+ if($ph->is_valid()) {
+ $ph->scaleImage(max($width, $height));
+ $data = $ph->imageString();
+ $type = $ph->getType();
+ }
+ }
+
logger('fix_private_photos: replacing photo', LOGGER_DEBUG);
- $s = str_replace($image, 'data:' . $r[0]['type'] . ';base64,' . base64_encode($r[0]['data']), $s);
- logger('fix_private_photos: replaced: ' . $s, LOGGER_DATA);
+ $image = 'data:' . $type . ';base64,' . base64_encode($data);
+ logger('fix_private_photos: replaced: ' . $image, LOGGER_DATA);
}
}
}
}
+
+ $new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/img]';
+ $orig_body = substr($orig_body, $img_start + $img_st_close + $img_len + strlen('[/img]'));
+ if($orig_body === false)
+ $orig_body = '';
+
+ $img_start = strpos($orig_body, '[img');
+ $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+ $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
}
- return($s);
+
+ $new_body = $new_body . $orig_body;
+
+ return($new_body);
}
@@ -3245,10 +3779,23 @@ function drop_item($id,$interactive = true) {
$owner = $item['uid'];
+ $cid = 0;
+
// check if logged in user is either the author or owner of this item
- if((local_user() == $item['uid']) || (remote_user() == $item['contact-id'])) {
+ if(is_array($_SESSION['remote'])) {
+ foreach($_SESSION['remote'] as $visitor) {
+ if($visitor['uid'] == $item['uid'] && $visitor['cid'] == $item['contact-id']) {
+ $cid = $visitor['cid'];
+ break;
+ }
+ }
+ }
+
+ if((local_user() == $item['uid']) || ($cid) || (! $interactive)) {
+
+ logger('delete item: ' . $item['id'], LOGGER_DEBUG);
// delete the item
$r = q("UPDATE `item` SET `deleted` = 1, `title` = '', `body` = '', `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
@@ -3341,40 +3888,8 @@ function drop_item($id,$interactive = true) {
);
}
- // Add a relayable_retraction signature for Diaspora. 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
- $signed_text = $item['guid'] . ';' . ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment');
-
- if(local_user() == $item['uid']) {
-
- $handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
- $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha256'));
- }
- else {
- $r = q("SELECT `nick`, `url` FROM `contact` WHERE `id` = '%d' LIMIT 1",
- $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)
- );
+ // Add a relayable_retraction signature for Diaspora.
+ store_diaspora_retract_sig($item, $a->user, $a->get_baseurl());
}
$drop_id = intval($item['id']);
@@ -3429,7 +3944,9 @@ function posted_dates($uid,$wall) {
$dnow = substr($dthen,0,8) . '28';
$ret = array();
- while($dnow >= $dthen) {
+ // Starting with the current month, get the first and last days of every
+ // month down to and including the month of the first post
+ while(substr($dnow, 0, 7) >= substr($dthen, 0, 7)) {
$dstart = substr($dnow,0,8) . '01';
$dend = substr($dnow,0,8) . get_dim(intval($dnow),intval(substr($dnow,5)));
$start_month = datetime_convert('','',$dstart,'Y-m-d');
@@ -3461,4 +3978,52 @@ function posted_date_widget($url,$uid,$wall) {
'$dates' => $ret
));
return $o;
-}
\ No newline at end of file
+}
+
+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;
+}
diff --git a/include/lock.php b/include/lock.php
new file mode 100644
index 000000000..707e33609
--- /dev/null
+++ b/include/lock.php
@@ -0,0 +1,75 @@
+
+ Copyright (C)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ , 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/include/markdownify/TODO b/include/markdownify/TODO
new file mode 100644
index 000000000..06ec8508b
--- /dev/null
+++ b/include/markdownify/TODO
@@ -0,0 +1,29 @@
+Markdownify
+===========
+* handle non-markdownifiable lists (i.e. `
asdf
`)
+* organize methods better (i.e. flushlinebreaks & setlinebreaks close to each other)
+* take a look at function names etc.
+* is the new (in rev. 93) lastclosedtag property needed?
+* word wrapping (some work is done but it's still very buggy)
+
+
+Markdownify Extra
+=================
+
+* handle table alignment with KEEP_HTML=false
+* handle tables without headings when KEEP_HTML=false is set
+* handle Markdown inside non-markdownable tags
+
+
+Implementation Thoughts
+=======================
+* non-markdownifiable lists and markdown inside non-markdownable tags as well as the current
+ table implementation could be rewritten by using a rollback mechanism.
+
+ example:
+
+
asdf
asdf
+
+ we come to `
`, know that this might fail and create a snapshot of our current parser
+ we keep on parsing and when we reach `
` we gotta rollback and keep this
+ list in HTML format.
diff --git a/include/markdownify/example.php b/include/markdownify/example.php
new file mode 100644
index 000000000..ef86dca83
--- /dev/null
+++ b/include/markdownify/example.php
@@ -0,0 +1,51 @@
+parseString($_POST['input']);
+ } else {
+ $_POST['input'] = '';
+ }
+?>
+
+
+
+ HTML to Markdown Converter
+
+
+
+
+
+
#Us', array(&$this, '_makeFootnotes'), $html);
+ return parent::parseString($html);
+ }
+ /**
+ * replace HTML representation of footnotes with something more easily parsable
+ *
+ * @note this is a callback to be used in parseString()
+ *
+ * @param array $matches
+ * @return string
+ */
+ function _makeFootnotes($matches) {
+ #