From eb2ef6dec43391631e2989b55bc4d762336680ca Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 22 Aug 2011 18:52:02 -0700 Subject: diaspora admin toggle, update install guide --- include/acl_selectors.php | 2 +- include/network.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 48ba77a88..66fe104ea 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -170,7 +170,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p $sql_extra .= " AND `network` IN ( 'dfrn' ) "; } elseif($privatenet) { - $sql_extra .= " AND `network` IN ( 'dfrn', 'mail', 'face' ) "; + $sql_extra .= " AND `network` IN ( 'dfrn', 'mail', 'face', 'dspr' ) "; } diff --git a/include/network.php b/include/network.php index d4f0d8aa7..f0dd828d1 100644 --- a/include/network.php +++ b/include/network.php @@ -508,7 +508,7 @@ function fetch_xrd_links($url) { $xrd_timeout = intval(get_config('system','xrd_timeout')); $redirects = 0; - $xml = fetch_url($url,false,$redirects,(($xrd_timeout) ? $xrd_timeout : 30)); + $xml = fetch_url($url,false,$redirects,(($xrd_timeout) ? $xrd_timeout : 20)); logger('fetch_xrd_links: ' . $xml, LOGGER_DATA); -- cgit v1.2.3 From b0211499c1990792eaa501e86c984d67d4cd4f39 Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 22 Aug 2011 19:27:40 -0700 Subject: invoke notifier --- include/diaspora.php | 88 ++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 47 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index f3adc608e..78a642048 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -3,6 +3,43 @@ require_once('include/crypto.php'); require_once('include/items.php'); +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), + intval($uid), + dbesc($handle) + ); + if($r && count($r)) + return $r[0]; + return false; +} + +function find_diaspora_person_by_handle($handle) { + $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1", + dbesc(NETWORK_DIASPORA), + dbesc($handle) + ); + if(count($r)) { + // update record occasionally so it doesn't get stale + $d = strtotime($r[0]['updated'] . ' +00:00'); + if($d < strtotime('now - 14 days')) { + q("delete from fcontact where id = %d limit 1", + intval($r[0]['id']) + ); + } + else + return $r[0]; + } + require_once('include/Scrape.php'); + $r = probe_url($handle, PROBE_DIASPORA); + if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) { + add_fcontact($r); + return ($r); + } + return false; +} + + function get_diaspora_key($uri) { logger('Fetching diaspora key for: ' . $uri); @@ -13,16 +50,6 @@ function get_diaspora_key($uri) { } -function diaspora_base_message($type,$data) { - - $tpl = get_markup_template('diaspora_' . $type . '.tpl'); - if(! $tpl) - return ''; - return replace_macros($tpl,$data); - -} - - function diaspora_msg_build($msg,$user,$contact,$prvkey,$pubkey) { $a = get_app(); @@ -262,42 +289,6 @@ function diaspora_decode($importer,$xml) { } -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), - intval($uid), - dbesc($handle) - ); - if($r && count($r)) - return $r[0]; - return false; -} - -function find_diaspora_person_by_handle($handle) { - $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1", - dbesc(NETWORK_DIASPORA), - dbesc($handle) - ); - if(count($r)) { - // update record occasionally so it doesn't get stale - $d = strtotime($r[0]['updated'] . ' +00:00'); - if($d < strtotime('now - 14 days')) { - q("delete from fcontact where id = %d limit 1", - intval($r[0]['id']) - ); - } - else - return $r[0]; - } - require_once('include/Scrape.php'); - $r = probe_url($handle, PROBE_DIASPORA); - if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) { - add_fcontact($r); - return ($r); - } - return false; -} - function diaspora_request($importer,$xml) { @@ -599,6 +590,8 @@ function diaspora_comment($importer,$xml,$msg) { } // notify others + proc_run('php','include/notifier.php','comment',$message_id); + return; } @@ -768,7 +761,8 @@ EOT; ); } - // FIXME send notification + // notify others + proc_run('php','include/notifier.php','comment',$message_id); return; } -- cgit v1.2.3 From b9e4668f68321bd767dfffb626be940e0b1be460 Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 22 Aug 2011 20:35:34 -0700 Subject: d* retractions --- include/diaspora.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 78a642048..4420129b0 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -771,19 +771,32 @@ function diaspora_retraction($importer,$xml) { $guid = notags(unxmlify($xml->guid)); $diaspora_handle = notags(unxmlify($xml->diaspora_handle)); + $type = notags(unxmlify($xml->type)); $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle); if(! $contact) return; -// if(($contact['rel'] == CONTACT_IS_FOLLOWER) || ($contact['blocked']) || ($contact['readonly'])) { -// logger('diaspora_retraction: Ignoring this author.'); -// http_status_exit(202); -// // NOTREACHED -// } - - + if($type === 'Person') { + contact_remove($contact['id']); + } + elseif($type === 'Post') { + $r = q("select * from item where guid = '%s' and uid = %d limit 1", + dbesc('guid'), + intval($importer['uid']) + ); + if(count($r)) { + if(link_compare($r[0]['author-link'],$contact['url'])) { + q("update item set `deleted` = 1, `changed` = '%s' where `id` = %d limit 1", + dbesc(datetime_convert()), + intval($r[0]['id']) + ); + } + } + } + http_exit_status(202); + // NOTREACHED } function diaspora_share($me,$contact) { @@ -805,6 +818,28 @@ function diaspora_share($me,$contact) { return $return_code; } +function diaspora_unshare($me,$contact) { + + $a = get_app(); + $myaddr = $me['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + + $tpl = get_markup_template('diaspora_retract.tpl'); + $msg = replace_macros($tpl, array( + '$guid' => $me['guid'], + '$type' => 'Person', + '$handle' => $myaddr + )); + + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey']))); + + post_url($contact['notify'] . '/',$slap); + $return_code = $a->get_curl_code(); + logger('diaspora_send_unshare: returns: ' . $return_code); + return $return_code; +} + + + function diaspora_send_status($item,$owner,$contact) { $a = get_app(); @@ -975,8 +1010,21 @@ function diaspora_send_relay($item,$owner,$contact) { function diaspora_send_retraction($item,$owner,$contact) { + $a = get_app(); + $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); + $tpl = get_markup_template('diaspora_retract.tpl'); + $msg = replace_macros($tpl, array( + '$guid' => $item['guid'], + '$type' => 'Post', + '$handle' => $myaddr + )); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey']))); + post_url($contact['notify'] . '/',$slap); + $return_code = $a->get_curl_code(); + logger('diaspora_send_retraction: returns: ' . $return_code); + return $return_code; } \ No newline at end of file -- cgit v1.2.3 From 58651f7eb83e1be1f2dffc6f88370187be2f3943 Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 22 Aug 2011 21:15:31 -0700 Subject: public posts ~f to D* --- include/notifier.php | 79 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 23 deletions(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index cf8871fb9..5cbd3deb1 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -139,7 +139,7 @@ function notifier_run($argv, $argc){ $hub = get_config('system','huburl'); // If this is a public conversation, notify the feed hub - $notify_hub = true; + $public_message = true; // fill this in with a single salmon slap if applicable $slap = ''; @@ -153,7 +153,7 @@ function notifier_run($argv, $argc){ if($parent['wall'] == 0 && (! $expire)) { // local followup to remote post $followup = true; - $notify_hub = false; // not public + $public_message = false; // not public $conversant_str = dbesc($parent['contact-id']); } else { @@ -163,7 +163,7 @@ function notifier_run($argv, $argc){ || (strlen($parent['allow_gid'])) || (strlen($parent['deny_cid'])) || (strlen($parent['deny_gid']))) { - $notify_hub = false; // private recipients, not public + $public_message = false; // private recipients, not public } $allow_people = expand_acl($parent['allow_cid']); @@ -177,7 +177,7 @@ function notifier_run($argv, $argc){ $recipients[] = $item['contact-id']; $conversants[] = $item['contact-id']; // pull out additional tagged people to notify (if public message) - if($notify_hub && strlen($item['inform'])) { + if($public_message && strlen($item['inform'])) { $people = explode(',',$item['inform']); foreach($people as $person) { if(substr($person,0,4) === 'cid:') { @@ -241,7 +241,7 @@ function notifier_run($argv, $argc){ )); if($cmd === 'mail') { - $notify_hub = false; // mail is not public + $public_message = false; // mail is not public $body = fix_private_photos($item['body'],$owner['uid']); @@ -257,7 +257,7 @@ function notifier_run($argv, $argc){ )); } elseif($cmd === 'suggest') { - $notify_hub = false; // suggestions are not public + $public_message = false; // suggestions are not public $sugg_template = get_markup_template('atom_suggest.tpl'); @@ -296,7 +296,7 @@ function notifier_run($argv, $argc){ // private emails may be in included in public conversations. Filter them. - if(($notify_hub) && $item['private']) + if(($public_message) && $item['private']) continue; $contact = get_item_contact($item,$contacts); @@ -305,7 +305,7 @@ function notifier_run($argv, $argc){ $atom .= atom_entry($item,'text',$contact,$owner,true); - if(($top_level) && ($notify_hub) && ($item['author-link'] === $item['owner-link']) && (! $expire)) + if(($top_level) && ($public_message) && ($item['author-link'] === $item['owner-link']) && (! $expire)) $slaps[] = atom_entry($item,'html',$contact,$owner,true); } } @@ -403,7 +403,7 @@ function notifier_run($argv, $argc){ // only send salmon if public - e.g. if it's ok to notify // a public hub, it's ok to send a salmon - if((count($slaps)) && ($notify_hub) && (! $expire)) { + if((count($slaps)) && ($public_message) && (! $expire)) { logger('notifier: slapdelivery: ' . $contact['name']); foreach($slaps as $slappy) { if($contact['notify']) { @@ -544,7 +544,7 @@ function notifier_run($argv, $argc){ // send additional slaps to mentioned remote tags (@foo@example.com) - if($slap && count($url_recipients) && ($followup || $top_level) && $notify_hub && (! $expire)) { + if($slap && count($url_recipients) && ($followup || $top_level) && $public_message && (! $expire)) { if(! get_config('system','dfrn_only')) { foreach($url_recipients as $url) { if($url) { @@ -556,7 +556,7 @@ function notifier_run($argv, $argc){ } } - if((strlen($hub)) && ($notify_hub)) { + if((strlen($hub)) && ($public_message)) { $hubs = explode(',', $hub); if(count($hubs)) { foreach($hubs as $h) { @@ -572,12 +572,12 @@ function notifier_run($argv, $argc){ } } - if($notify_hub) { + if($public_message) { /** * * If you have less than 999 dfrn friends and it's a public message, - * we'll just go ahead and push them out securely with dfrn/rino. + * we'll just go ahead and push them out securely with dfrn/rino or Diaspora. * If you've got more than that, you'll have to rely on PuSH delivery. * */ @@ -592,9 +592,10 @@ function notifier_run($argv, $argc){ */ $r = q("SELECT `id`, `name` FROM `contact` - WHERE `network` = '%s' AND `uid` = %d AND `blocked` = 0 AND `pending` = 0 + WHERE `network` in ('%s','%s') AND `uid` = %d AND `blocked` = 0 AND `pending` = 0 AND `rel` != %d ", dbesc(NETWORK_DFRN), + dbesc(NETWORK_DIASPORA), intval($owner['uid']), intval(CONTACT_IS_SHARING) ); @@ -607,19 +608,51 @@ function notifier_run($argv, $argc){ /* Don't deliver to folks who have already been delivered to */ - if(! in_array($rr['id'], $conversants)) { - $n = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", - intval($rr['id']) - ); + if(in_array($rr['id'],$conversants)) + continue; + + $n = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", + intval($rr['id']) + ); - if(count($n)) { + if(count($n)) { + switch($n[0]['network']) { + case NETWORK_DFRN : + logger('notifier: dfrnpubdelivery: ' . $n[0]['name']); + $deliver_status = dfrn_deliver($owner,$n[0],$atom); + break; + case NETWORK_DIASPORA : + require_once('include/diaspora.php'); + if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) + break; - logger('notifier: dfrnpubdelivery: ' . $n[0]['name']); - $deliver_status = dfrn_deliver($owner,$n[0],$atom); + if($target_item['verb'] === ACTIVITY_DISLIKE) { + // unsupported + break; + } + elseif($target_item['deleted'] && (! $parent_item['verb'] === ACTIVITY_LIKE)) { + // diaspora delete, + diaspora_send_retraction($target_item,$owner,$n[0]); + break; + } + elseif($followup) { + // send comments, likes and retractions of likes to owner to relay + diaspora_send_followup($target_item,$owner,$n[0]); + break; + } + elseif($target_item['parent'] != $target_item['id']) { + // we are the relay - send comments, likes and unlikes to our conversants + diaspora_send_relay($target_item,$owner,$n[0]); + break; + } + elseif($top_level) { + diaspora_send_status($target_item,$owner,$n[0]); + break; + } + default: + break; } } - else - logger('notifier: dfrnpubdelivery: ignoring ' . $rr['name']); } } } -- cgit v1.2.3 From 56ea11a5616ad5f17a81078fa8251a8c15ec7fd4 Mon Sep 17 00:00:00 2001 From: Friendika Date: Mon, 22 Aug 2011 23:18:22 -0700 Subject: bad param in like function --- include/diaspora.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 4420129b0..58dd579bc 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -907,7 +907,7 @@ function diaspora_send_followup($item,$owner,$contact) { else $signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . ';' . $myaddr; - $authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey']),'sha'); + $authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha')); $msg = replace_macros($tpl,array( '$guid' => xmlify($item['guid']), -- cgit v1.2.3 From 561051e805e3f262ed5e8e5f712e2e514ecb90b8 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 01:00:29 -0700 Subject: convert bbcode to markdown for diaspora (first try, will need tweaking) --- include/bb2diaspora.php | 154 ++++++++++++++++++++++++++++++++++++++++++++++++ include/diaspora.php | 10 ++-- 2 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 include/bb2diaspora.php (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php new file mode 100644 index 000000000..a4e7997fa --- /dev/null +++ b/include/bb2diaspora.php @@ -0,0 +1,154 @@ +', '', $s[1]) . '[/code]'; +} + + + // BBcode 2 HTML was written by WAY2WEB.net + // extended to work with Mistpark/Friendika - Mike Macgirvin + +function bb2diaspora($Text,$preserve_nl = false) { + + // Replace any html brackets with HTML Entities to prevent executing HTML or script + // Don't use strip_tags here because it breaks [url] search by replacing & with amp + + $Text = str_replace("<", "<", $Text); + $Text = str_replace(">", ">", $Text); + + + if($preserve_nl) + $Text = str_replace(array("\n","\r"), array('',''),$Text); + + // Set up the parameters for a URL search string + $URLSearchString = "^\[\]"; + // Set up the parameters for a MAIL search string + $MAILSearchString = $URLSearchString; + + // Perform URL Search + + + + $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '[$1]($1)', $Text); + $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.*?)\[/url\])", '[$2]($1)', $Text); + //$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '[$2]($1)', $Text); + + + // Perform MAIL Search + $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text); + $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '[$2](mailto:$1)', $Text); + + // Check for bold text + $Text = preg_replace("(\[b\](.*?)\[\/b\])is",'**$1**',$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 strike-through text +// $Text = preg_replace("(\[s\](.*?)\[\/s\])is",'$1',$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); + + // Check for sized text +// $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])is","$2",$Text); + + // Check for list text +// $Text = preg_replace("/\[list\](.*?)\[\/list\]/is", '
    $1
' ,$Text); +// $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/is", '
    $1
' ,$Text); +// $Text = preg_replace("/\[list=i\](.*?)\[\/list\]/s",'
    $1
' ,$Text); +// $Text = preg_replace("/\[list=I\](.*?)\[\/list\]/s", '
    $1
' ,$Text); +// $Text = preg_replace("/\[list=a\](.*?)\[\/list\]/s", '
    $1
' ,$Text); +// $Text = preg_replace("/\[list=A\](.*?)\[\/list\]/s", '
    $1
' ,$Text); +// $Text = preg_replace("/\[li\](.*?)\[\/li\]/s", '
  • $1
  • ' ,$Text); + +// $Text = preg_replace("/\[td\](.*?)\[\/td\]/s", '$1' ,$Text); +// $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/s", '$1' ,$Text); +// $Text = preg_replace("/\[table\](.*?)\[\/table\]/s", '$1
    ' ,$Text); + +// $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/s", '$1
    ' ,$Text); +// $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/s", '$1
    ' ,$Text); + + +// $Text = str_replace("[*]", "
  • ", $Text); + + // Check for font change text +// $Text = preg_replace("(\[font=(.*?)\](.*?)\[\/font\])","$2",$Text); + + // Declare the format for [code] layout + + $Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/is",'stripdcode_br_cb',$Text); + +// $CodeLayout = '$1'; + // Check for [code] text +// $Text = preg_replace("/\[code\](.*?)\[\/code\]/is","$CodeLayout", $Text); + + + + + // Declare the format for [quote] layout +// $QuoteLayout = '
    $1
    '; + // Check for [quote] text +// $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/is","$QuoteLayout", $Text); + + // Images + // [img]pathtoimage[/img] +// $Text = preg_replace("/\[img\](.*?)\[\/img\]/", '' . t('Image/photo') . '', $Text); + + // html5 video and audio + +// $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '', $Text); + +// $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '', $Text); + +// $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/", '', $Text); + + // [img=widthxheight]image source[/img] +// $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/", '', $Text); + +// if (get_pconfig(local_user(), 'oembed', 'use_for_youtube' )==1){ +// // use oembed for youtube links +// $Text = preg_replace("/\[youtube\]/",'[embed]',$Text); +// $Text = preg_replace("/\[\/youtube\]/",'[/embed]',$Text); +// } else { +// // Youtube extensions + // $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); + // $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); +// $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); +// } +// $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); + + + + // oembed tag +// $Text = oembed_bbcode2html($Text); + + // If we found an event earlier, strip out all the event code and replace with a reformatted version. + +// if(x($ev,'desc') && x($ev,'start')) { +// $sub = format_event_html($ev); + + // $Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/is",$sub,$Text); + //$Text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/is",'',$Text); +// $Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/is",'',$Text); +// $Text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/is",'',$Text); +// $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",'',$Text); +// } + + + + call_hooks('bb2diaspora',$Text); + + return $Text; +} diff --git a/include/diaspora.php b/include/diaspora.php index 58dd579bc..b841c7770 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -845,9 +845,9 @@ function diaspora_send_status($item,$owner,$contact) { $a = get_app(); $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); $theiraddr = $contact['addr']; - require_once('include/bbcode.php'); + require_once('include/bb2diaspora.php'); - $body = xmlify(bbcode($item['body'])); + $body = xmlify(bb2diaspora($item['body'])); $public = (($item['private']) ? 'false' : 'true'); require_once('include/datetime.php'); @@ -898,12 +898,12 @@ function diaspora_send_followup($item,$owner,$contact) { $like = false; } - $text = bbcode($item['body']); + $text = bb2diaspora($item['body']); // sign it if($like) - $signed_text = $item['guid'] . ';' . $target_type . ';' . $positive . ';' . $myaddr; + $signed_text = $item['guid'] . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $myaddr; else $signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . ';' . $myaddr; @@ -966,7 +966,7 @@ function diaspora_send_relay($item,$owner,$contact) { $like = false; } - $text = bbcode($item['body']); + $text = bb2diaspora($item['body']); // sign it -- cgit v1.2.3 From c1a1b2ab60b9c19d49580869a0835b0be6f0eb0d Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 01:33:58 -0700 Subject: updates bb2md --- include/bb2diaspora.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index a4e7997fa..007a2bf35 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -32,6 +32,8 @@ function bb2diaspora($Text,$preserve_nl = false) { // Perform URL Search + // [img]pathtoimage[/img] + $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('Image/photo: ') . '$1', $Text); $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '[$1]($1)', $Text); @@ -43,6 +45,11 @@ function bb2diaspora($Text,$preserve_nl = false) { $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); + + $Text = str_replace('`','\\`', $Text); + // Check for bold text $Text = preg_replace("(\[b\](.*?)\[\/b\])is",'**$1**',$Text); @@ -92,7 +99,7 @@ function bb2diaspora($Text,$preserve_nl = false) { // $CodeLayout = '$1'; // Check for [code] text -// $Text = preg_replace("/\[code\](.*?)\[\/code\]/is","$CodeLayout", $Text); + $Text = preg_replace("/\[code\](.*?)\[\/code\]/is","```$1```", $Text); @@ -103,8 +110,6 @@ function bb2diaspora($Text,$preserve_nl = false) { // $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/is","$QuoteLayout", $Text); // Images - // [img]pathtoimage[/img] -// $Text = preg_replace("/\[img\](.*?)\[\/img\]/", '' . t('Image/photo') . '', $Text); // html5 video and audio -- cgit v1.2.3 From 508f22f859eb8e450f705a401e72bb2ee2cd72ef Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 01:47:42 -0700 Subject: photos a bit messed up on d* --- include/bb2diaspora.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 007a2bf35..3d5846432 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -33,13 +33,12 @@ function bb2diaspora($Text,$preserve_nl = false) { // Perform URL Search // [img]pathtoimage[/img] - $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('Image/photo: ') . '$1', $Text); $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '[$1]($1)', $Text); $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.*?)\[/url\])", '[$2]($1)', $Text); - //$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '[$2]($1)', $Text); + $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('Image/photo: ') . '$1', $Text); // Perform MAIL Search $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text); -- cgit v1.2.3 From 124881903ef1c6bd6717b14074538007a01da89a Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 01:51:37 -0700 Subject: forget about the image link we have it in the wrapper --- include/bb2diaspora.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 3d5846432..0dae9ae45 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -38,7 +38,7 @@ function bb2diaspora($Text,$preserve_nl = false) { $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '[$1]($1)', $Text); $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.*?)\[/url\])", '[$2]($1)', $Text); - $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('Image/photo: ') . '$1', $Text); +// $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('Image/photo: ') . '$1', $Text); // Perform MAIL Search $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text); -- cgit v1.2.3 From c55d24b451cfab81b68452064951f1ada4ff9d1f Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 01:52:59 -0700 Subject: second try --- include/bb2diaspora.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 0dae9ae45..ceda4b69c 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -39,6 +39,7 @@ function bb2diaspora($Text,$preserve_nl = false) { $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.*?)\[/url\])", '[$2]($1)', $Text); // $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('Image/photo: ') . '$1', $Text); + $Text = preg_replace("/\[img\](.*?)\[\/img\]/", '', $Text); // Perform MAIL Search $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text); -- cgit v1.2.3 From 92504b5df77bb53bc40b7e105e8c7a759995dd30 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 01:55:46 -0700 Subject: more testing with images --- include/bb2diaspora.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index ceda4b69c..3baba8a9e 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -39,7 +39,7 @@ function bb2diaspora($Text,$preserve_nl = false) { $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.*?)\[/url\])", '[$2]($1)', $Text); // $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('Image/photo: ') . '$1', $Text); - $Text = preg_replace("/\[img\](.*?)\[\/img\]/", '', $Text); + $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('image/photo'), $Text); // Perform MAIL Search $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text); -- cgit v1.2.3 From 8cfbe2c432e658fe67b0b21ba411a751f50d8f0c Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 03:02:31 -0700 Subject: include bb2diaspora at top level --- include/diaspora.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index b841c7770..345ea5562 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2,6 +2,7 @@ require_once('include/crypto.php'); require_once('include/items.php'); +require_once('include/bb2diaspora.php'); function diaspora_get_contact_by_handle($uid,$handle) { $r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `addr` = '%s' LIMIT 1", @@ -845,7 +846,6 @@ function diaspora_send_status($item,$owner,$contact) { $a = get_app(); $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); $theiraddr = $contact['addr']; - require_once('include/bb2diaspora.php'); $body = xmlify(bb2diaspora($item['body'])); $public = (($item['private']) ? 'false' : 'true'); -- cgit v1.2.3 From afbc46c00f3fcd66603bb6b725fd687335376d2d Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 03:06:08 -0700 Subject: don't process diaspora communications if no pubkey --- include/notifier.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index 5cbd3deb1..14057c35b 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -505,6 +505,9 @@ function notifier_run($argv, $argc){ require_once('include/diaspora.php'); if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) break; + + if(! contact['pubkey']) + break; if($target_item['verb'] === ACTIVITY_DISLIKE) { // unsupported @@ -625,6 +628,9 @@ function notifier_run($argv, $argc){ require_once('include/diaspora.php'); if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) break; + + if(! contact['pubkey']) + break; if($target_item['verb'] === ACTIVITY_DISLIKE) { // unsupported -- cgit v1.2.3 From 0739ae315bdc4d9d8d7c5021d34fc14860431c41 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 03:07:26 -0700 Subject: typo --- include/notifier.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index 14057c35b..93df670f1 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -506,7 +506,7 @@ function notifier_run($argv, $argc){ if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) break; - if(! contact['pubkey']) + if(! $contact['pubkey']) break; if($target_item['verb'] === ACTIVITY_DISLIKE) { @@ -629,7 +629,7 @@ function notifier_run($argv, $argc){ if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) break; - if(! contact['pubkey']) + if(! $contact['pubkey']) break; if($target_item['verb'] === ACTIVITY_DISLIKE) { -- cgit v1.2.3 From 99681e33af20bc35e6992eb1e8869fb6ebcce39e Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 03:49:38 -0700 Subject: testing retractions --- include/notifier.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index 93df670f1..4068a9fae 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -513,7 +513,7 @@ function notifier_run($argv, $argc){ // unsupported break; } - elseif($target_item['deleted'] && (! $parent_item['verb'] === ACTIVITY_LIKE)) { + elseif($target_item['deleted'] && (! $target_item['verb'] === ACTIVITY_LIKE)) { // diaspora delete, diaspora_send_retraction($target_item,$owner,$contact); break; @@ -628,7 +628,7 @@ function notifier_run($argv, $argc){ require_once('include/diaspora.php'); if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) break; - + if(! $contact['pubkey']) break; @@ -636,7 +636,7 @@ function notifier_run($argv, $argc){ // unsupported break; } - elseif($target_item['deleted'] && (! $parent_item['verb'] === ACTIVITY_LIKE)) { + elseif($target_item['deleted'] && (! $target_item['verb'] === ACTIVITY_LIKE)) { // diaspora delete, diaspora_send_retraction($target_item,$owner,$n[0]); break; -- cgit v1.2.3 From 91de9edecd2663d5e3313da1b8a01a35e7e8970e Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 04:02:29 -0700 Subject: retractions - precedence issue --- include/notifier.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index 4068a9fae..55d74eb5f 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -513,7 +513,7 @@ function notifier_run($argv, $argc){ // unsupported break; } - elseif($target_item['deleted'] && (! $target_item['verb'] === ACTIVITY_LIKE)) { + elseif(($target_item['deleted']) && ($target_item['verb'] !== ACTIVITY_LIKE)) { // diaspora delete, diaspora_send_retraction($target_item,$owner,$contact); break; @@ -636,7 +636,7 @@ function notifier_run($argv, $argc){ // unsupported break; } - elseif($target_item['deleted'] && (! $target_item['verb'] === ACTIVITY_LIKE)) { + elseif(($target_item['deleted']) && ($target_item['verb'] !== ACTIVITY_LIKE)) { // diaspora delete, diaspora_send_retraction($target_item,$owner,$n[0]); break; -- cgit v1.2.3 From 56d64316f457c85141e35356a61a4d352ed9f24c Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 18:17:35 -0700 Subject: diaspora photos ? --- include/Photo.php | 13 +++++- include/diaspora.php | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++- include/group.php | 5 ++- include/poller.php | 8 +++- 4 files changed, 136 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/Photo.php b/include/Photo.php index de4c3d9e0..1450374ff 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -185,11 +185,20 @@ class Photo { public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { + $r = q("select `guid` from photo where `resource-id` = '%s' and `guid` != '' limit 1", + dbesc($rid) + ); + if(count($r)) + $guid = $r[0]['guid']; + else + $guid = get_guid(); + $r = q("INSERT INTO `photo` - ( `uid`, `contact-id`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) - VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )", + ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) + VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s' )", intval($uid), intval($cid), + dbesc($guid), dbesc($rid), dbesc(datetime_convert()), dbesc(datetime_convert()), diff --git a/include/diaspora.php b/include/diaspora.php index 345ea5562..a1edd08a6 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -597,6 +597,57 @@ function diaspora_comment($importer,$xml,$msg) { } +function diaspora_photo($importer,$xml,$msg) { + + $remote_photo_path = notags(unxmlify($xml->remote_photo_path)); + + $remote_photo_name = notags(unxmlify($xml->remote_photo_name)); + + $status_message_guid = notags(unxmlify($xml->status_message_guid)); + + $guid = notags(unxmlify($xml->guid)); + + $diaspora_handle = notags(unxmlify($xml->diaspora_handle)); + + $public = notags(unxmlify($xml->public)); + + $created_at = notags(unxmlify($xml_created_at)); + + + $contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']); + if(! $contact) + return; + + if(($contact['rel'] == CONTACT_IS_FOLLOWER) || ($contact['blocked']) || ($contact['readonly'])) { + logger('diaspora_photo: Ignoring this author.'); + http_status_exit(202); + // NOTREACHED + } + + $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", + intval($importer['uid']), + dbesc($status_message_guid) + ); + if(! count($r)) { + logger('diaspora_photo: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid); + return; + } + $parent_item = $r[0]; + + $link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n"; + + $r = q("update item set `body` = '%s' where `id` = %d and `uid` = %d limit 1", + dbesc($link_text . $parent_item['body']), + intval($parent_item['id']), + intval($parent_item['uid']) + ); + + return; +} + + + + function diaspora_like($importer,$xml,$msg) { $a = get_app(); @@ -847,7 +898,25 @@ function diaspora_send_status($item,$owner,$contact) { $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); $theiraddr = $contact['addr']; - $body = xmlify(bb2diaspora($item['body'])); + $images = array(); + + $body = $item['body']; + + $cnt = preg_match_all('|\[img\](.*?)\[\/img\]|',$body,$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + $detail = array(); + $detail['str'] = $mtch[0]; + $detail['path'] = dirname($mtch[1]); + $detail['file'] = basename($mtch[1]); + $detail['guid'] = $item['guid']; + $detail['handle'] = $myaddr; + $images[] = $detail; + $body = str_replace($detail['str'],'',$body); + } + } + + $body = xmlify(bb2diaspora($body)); $public = (($item['private']) ? 'false' : 'true'); require_once('include/datetime.php'); @@ -869,10 +938,55 @@ function diaspora_send_status($item,$owner,$contact) { post_url($contact['notify'] . '/',$slap); $return_code = $a->get_curl_code(); logger('diaspora_send_status: returns: ' . $return_code); + + if(count($images)) { + diaspora_send_images($item,$owner,$contact,$images); + } + return $return_code; } +function diaspora_send_images($item,$owner,$contact,$images) { + $a = get_app(); + if(! count($images)) + return; + $mysite = substr($a->get_baseurl(),strpos($a->get_baseurl(),'://') + 3) . '/photo'; + + $tpl = get_markup_template('diaspora_photo.tpl'); + foreach($images as $image) { + if(! stristr($image['path'],$mysite)) + continue; + $resource = str_replace('.jpg','',$image['file']); + $resource = substr($resource,0,strpos($resource,'-')); + + $r = q("select * from photo where `resource-id` = '%s' and `uid` = %d limit 1", + dbesc($resource), + intval($owner['uid']) + ); + if(! count($r)) + continue; + $public = (($r[0]['allow_cid'] || $r[0]['allow_gid'] || $r[0]['deny_cid'] || $r[0]['deny_gid']) ? 'false' : 'true' ); + $msg = replace_macros($tpl,array( + '$path' => xmlify($image['path']), + '$filename' => xmlify($image['file']), + '$msg_guid' => xmlify($image['guid']), + '$guid' => xmlify($r[0]['guid']), + '$handle' => xmlify($image['handle']), + '$public' => xmlify($public), + '$created_at' => xmlify('UTC','UTC',$r[0]['created'],'Y-m-d h:i:s \U\T\C') + )); + + logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA); + $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey']))); + + post_url($contact['notify'] . '/',$slap); + $return_code = $a->get_curl_code(); + logger('diaspora_send_photo: returns: ' . $return_code); + } + +} + function diaspora_send_followup($item,$owner,$contact) { $a = get_app(); diff --git a/include/group.php b/include/group.php index 1ebae7b7b..5e3a1511a 100644 --- a/include/group.php +++ b/include/group.php @@ -124,9 +124,10 @@ function group_public_members($gid) { $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member` LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` WHERE `gid` = %d AND `group_member`.`uid` = %d - AND `contact`.`network` != 'dfrn' AND `contact`.`network` != 'mail' AND `contact`.`network` != 'face' ", + AND `contact`.`network` = '%' AND `contact`.`notify` != '' ", intval($gid), - intval(local_user()) + intval(local_user()), + dbesc(NETWORK_OSTATUS) ); if(count($r)) $ret = count($r); diff --git a/include/poller.php b/include/poller.php index 651736a99..e80b696bf 100644 --- a/include/poller.php +++ b/include/poller.php @@ -82,12 +82,18 @@ function poller_run($argv, $argc){ if(! $restart) proc_run('php','include/cronhooks.php'); + // Only poll from those with suitable relationships, + // and which have a polling address and ignore Diaspora since + // we are unable to match those posts with a Diaspora GUID and prevent duplicates. + $contacts = q("SELECT `id` FROM `contact` WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != '' + AND `network` != '%s' $sql_extra AND `self` = 0 AND `blocked` = 0 AND `readonly` = 0 ORDER BY RAND()", intval(CONTACT_IS_SHARING), - intval(CONTACT_IS_FRIEND) + intval(CONTACT_IS_FRIEND), + dbesc(NETWORK_DIASPORA) ); if(! count($contacts)) { -- cgit v1.2.3 From b41592f5563f0cf1e776a02da6771cd096d47943 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 18:22:15 -0700 Subject: fix group public members --- include/group.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/group.php b/include/group.php index 5e3a1511a..d69679484 100644 --- a/include/group.php +++ b/include/group.php @@ -124,7 +124,7 @@ function group_public_members($gid) { $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member` LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` WHERE `gid` = %d AND `group_member`.`uid` = %d - AND `contact`.`network` = '%' AND `contact`.`notify` != '' ", + AND ( `contact`.`network` = '%s' OR `contact`.`notify` != '' )", intval($gid), intval(local_user()), dbesc(NETWORK_OSTATUS) -- cgit v1.2.3 From 3b4da00495f17fd937ebdfc14b52106ac4d9a5f3 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 18:28:17 -0700 Subject: fix it again --- include/group.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/group.php b/include/group.php index d69679484..f21ce42e0 100644 --- a/include/group.php +++ b/include/group.php @@ -124,7 +124,7 @@ function group_public_members($gid) { $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member` LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` WHERE `gid` = %d AND `group_member`.`uid` = %d - AND ( `contact`.`network` = '%s' OR `contact`.`notify` != '' )", + AND ( `contact`.`network` = '%s' OR `contact`.`notify` = '' )", intval($gid), intval(local_user()), dbesc(NETWORK_OSTATUS) -- cgit v1.2.3 From c1acea330c7c497f85c587e5499718d170272040 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 18:50:18 -0700 Subject: photo fixes --- include/bb2diaspora.php | 2 +- include/diaspora.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 3baba8a9e..5ce34d666 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -39,7 +39,7 @@ function bb2diaspora($Text,$preserve_nl = false) { $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.*?)\[/url\])", '[$2]($1)', $Text); // $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('Image/photo: ') . '$1', $Text); - $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('image/photo'), $Text); +// $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('image/photo'), $Text); // Perform MAIL Search $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '[$1](mailto:$1)', $Text); diff --git a/include/diaspora.php b/include/diaspora.php index a1edd08a6..00bf1f910 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -907,12 +907,12 @@ function diaspora_send_status($item,$owner,$contact) { foreach($matches as $mtch) { $detail = array(); $detail['str'] = $mtch[0]; - $detail['path'] = dirname($mtch[1]); + $detail['path'] = dirname($mtch[1]) . '/'; $detail['file'] = basename($mtch[1]); $detail['guid'] = $item['guid']; $detail['handle'] = $myaddr; $images[] = $detail; - $body = str_replace($detail['str'],'',$body); + $body = str_replace($detail['str'],t('link to photo'),$body); } } @@ -931,7 +931,7 @@ function diaspora_send_status($item,$owner,$contact) { '$created' => $created )); - logger('diaspora_send_status: base message: ' . $msg, LOGGER_DATA); + 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']))); -- cgit v1.2.3 From 6a052c35865f21a094446a462c07f2b653ce209f Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 19:01:08 -0700 Subject: correct time in photo msg --- include/diaspora.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 00bf1f910..3c86b0037 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -912,7 +912,7 @@ function diaspora_send_status($item,$owner,$contact) { $detail['guid'] = $item['guid']; $detail['handle'] = $myaddr; $images[] = $detail; - $body = str_replace($detail['str'],t('link to photo'),$body); + $body = str_replace($detail['str'],t('link'),$body); } } @@ -974,7 +974,7 @@ function diaspora_send_images($item,$owner,$contact,$images) { '$guid' => xmlify($r[0]['guid']), '$handle' => xmlify($image['handle']), '$public' => xmlify($public), - '$created_at' => xmlify('UTC','UTC',$r[0]['created'],'Y-m-d h:i:s \U\T\C') + '$created_at' => xmlify(datetime_convert('UTC','UTC',$r[0]['created'],'Y-m-d h:i:s \U\T\C')) )); logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA); -- cgit v1.2.3 From 838d89a1104eae279fd80d337ce322560f0bda97 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 19:40:50 -0700 Subject: fix for public posts to D* --- include/notifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index 55d74eb5f..47dccc1bd 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -629,7 +629,7 @@ function notifier_run($argv, $argc){ if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) break; - if(! $contact['pubkey']) + if(! $n[0]['pubkey']) break; if($target_item['verb'] === ACTIVITY_DISLIKE) { -- cgit v1.2.3 From b57a01dc1418cc179ddd327af9d04a9e68e679e9 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 19:42:45 -0700 Subject: that was ugly - let's do better --- include/notifier.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index 47dccc1bd..1c8245c7a 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -619,17 +619,18 @@ function notifier_run($argv, $argc){ ); if(count($n)) { - switch($n[0]['network']) { + $contact = $n[0]; + switch($contact['network']) { case NETWORK_DFRN : - logger('notifier: dfrnpubdelivery: ' . $n[0]['name']); - $deliver_status = dfrn_deliver($owner,$n[0],$atom); + logger('notifier: dfrnpubdelivery: ' . $contact['name']); + $deliver_status = dfrn_deliver($owner,$contact,$atom); break; case NETWORK_DIASPORA : require_once('include/diaspora.php'); if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) break; - if(! $n[0]['pubkey']) + if(! $contact['pubkey']) break; if($target_item['verb'] === ACTIVITY_DISLIKE) { @@ -638,21 +639,21 @@ function notifier_run($argv, $argc){ } elseif(($target_item['deleted']) && ($target_item['verb'] !== ACTIVITY_LIKE)) { // diaspora delete, - diaspora_send_retraction($target_item,$owner,$n[0]); + diaspora_send_retraction($target_item,$owner,$contact); break; } elseif($followup) { // send comments, likes and retractions of likes to owner to relay - diaspora_send_followup($target_item,$owner,$n[0]); + diaspora_send_followup($target_item,$owner,$contact); break; } elseif($target_item['parent'] != $target_item['id']) { // we are the relay - send comments, likes and unlikes to our conversants - diaspora_send_relay($target_item,$owner,$n[0]); + diaspora_send_relay($target_item,$owner,$contact); break; } elseif($top_level) { - diaspora_send_status($target_item,$owner,$n[0]); + diaspora_send_status($target_item,$owner,$contact); break; } default: -- cgit v1.2.3 From 2cfdcee29a80e355307d013fe71d23a7300f8d98 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 23 Aug 2011 19:54:35 -0700 Subject: author and owner sign exactly the same string - apparently --- include/diaspora.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 3c86b0037..320f716bf 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -514,7 +514,8 @@ function diaspora_comment($importer,$xml,$msg) { if($parent_author_signature) { - $owner_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $msg['author']; +// $owner_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $msg['author']; + $owner_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $diaspora_handle; $parent_author_signature = base64_decode($parent_author_signature); @@ -734,7 +735,8 @@ function diaspora_like($importer,$xml,$msg) { } if($parent_author_signature) { - $owner_signed_data = $guid . ';' . $parent_guid . ';' . $target_type . ';' . $positive . ';' . $msg['author']; +// $owner_signed_data = $guid . ';' . $parent_guid . ';' . $target_type . ';' . $positive . ';' . $msg['author']; + $owner_signed_data = $guid . ';' . $parent_guid . ';' . $target_type . ';' . $positive . ';' . $diaspora_handle; $parent_author_signature = base64_decode($parent_author_signature); -- cgit v1.2.3 From 2aa23843e401e7f448c3d12f844934da6c27f8ef Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 24 Aug 2011 01:21:24 -0700 Subject: D* queue --- include/diaspora.php | 88 ++++++++++++++++++++++++++++++++++++---------------- include/queue.php | 13 ++++++++ 2 files changed, 75 insertions(+), 26 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 320f716bf..5ea38bad5 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -4,6 +4,36 @@ require_once('include/crypto.php'); require_once('include/items.php'); require_once('include/bb2diaspora.php'); +function diaspora_dispatch($importer,$msg) { + + $parsed_xml = parse_xml_string($msg['message'],false); + + $xmlbase = $parsed_xml->post; + + if($xmlbase->request) { + diaspora_request($importer,$xmlbase->request); + } + elseif($xmlbase->status_message) { + diaspora_post($importer,$xmlbase->status_message); + } + elseif($xmlbase->comment) { + diaspora_comment($importer,$xmlbase->comment,$msg); + } + elseif($xmlbase->like) { + diaspora_like($importer,$xmlbase->like,$msg); + } + elseif($xmlbase->retraction) { + diaspora_retraction($importer,$xmlbase->retraction,$msg); + } + elseif($xmlbase->photo) { + diaspora_photo($importer,$xmlbase->photo,$msg); + } + else { + logger('diaspora_dispatch: unknown message type: ' . print_r($xmlbase,true)); + } + return; +} + 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), @@ -866,10 +896,7 @@ function diaspora_share($me,$contact) { $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey']))); - post_url($contact['notify'] . '/',$slap); - $return_code = $a->get_curl_code(); - logger('diaspora_send_share: returns: ' . $return_code); - return $return_code; + return(diaspora_transmit($owner,$contact,$slap)); } function diaspora_unshare($me,$contact) { @@ -886,10 +913,8 @@ function diaspora_unshare($me,$contact) { $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey']))); - post_url($contact['notify'] . '/',$slap); - $return_code = $a->get_curl_code(); - logger('diaspora_send_unshare: returns: ' . $return_code); - return $return_code; + return(diaspora_transmit($owner,$contact,$slap)); + } @@ -937,9 +962,7 @@ function diaspora_send_status($item,$owner,$contact) { $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey']))); - post_url($contact['notify'] . '/',$slap); - $return_code = $a->get_curl_code(); - logger('diaspora_send_status: returns: ' . $return_code); + $return_code = diaspora_transmit($owner,$contact,$slap); if(count($images)) { diaspora_send_images($item,$owner,$contact,$images); @@ -979,12 +1002,11 @@ function diaspora_send_images($item,$owner,$contact,$images) { '$created_at' => xmlify(datetime_convert('UTC','UTC',$r[0]['created'],'Y-m-d h:i:s \U\T\C')) )); + logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA); $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey']))); - post_url($contact['notify'] . '/',$slap); - $return_code = $a->get_curl_code(); - logger('diaspora_send_photo: returns: ' . $return_code); + diaspora_transmit($owner,$contact,$slap); } } @@ -1039,11 +1061,7 @@ function diaspora_send_followup($item,$owner,$contact) { $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey']))); - post_url($contact['notify'] . '/',$slap); - $return_code = $a->get_curl_code(); - logger('diaspora_send_followup: returns: ' . $return_code); - return $return_code; - + return(diaspora_transmit($owner,$contact,$slap)); } @@ -1115,10 +1133,7 @@ function diaspora_send_relay($item,$owner,$contact) { $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey']))); - post_url($contact['notify'] . '/',$slap); - $return_code = $a->get_curl_code(); - logger('diaspora_send_relay: returns: ' . $return_code); - return $return_code; + return(diaspora_transmit($owner,$contact,$slap)); } @@ -1138,9 +1153,30 @@ function diaspora_send_retraction($item,$owner,$contact) { $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey']))); + return(diaspora_transmit($owner,$contact,$slap)); +} + + + +function diaspora_transmit($owner,$contact,$slap) { + + $a = get_app(); + post_url($contact['notify'] . '/',$slap); $return_code = $a->get_curl_code(); - logger('diaspora_send_retraction: returns: ' . $return_code); - return $return_code; + logger('diaspora_transmit: returns: ' . $return_code); + + if(! $return_code) { + logger('diaspora_transmit: queue message'); + // queue message for redelivery + q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`) + VALUES ( %d, '%s', '%s', '%s') ", + intval($contact['id']), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($slap) + ); + } -} \ No newline at end of file + return(($return_code) ? $return_code : (-1)); +} diff --git a/include/queue.php b/include/queue.php index fb65d5c25..da5028aee 100644 --- a/include/queue.php +++ b/include/queue.php @@ -56,6 +56,7 @@ function queue_run($argv, $argc){ // delivery loop require_once('include/salmon.php'); + require_once('include/diaspora.php'); foreach($r as $q_item) { @@ -120,6 +121,18 @@ function queue_run($argv, $argc){ remove_queue_item($q_item['id']); } break; + case NETWORK_DIASPORA: + if($contact['notify']) { + logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name']); + $deliver_status = diaspora_transmit($owner,$contact['notify'],$data); + + if($deliver_status == (-1)) + update_queue_time($q_item['id']); + else + remove_queue_item($q_item['id']); + } + break; + default: $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false); call_hooks('queue_deliver', $a, $params); -- cgit v1.2.3 From b6fdd3c76bd6d0f30a7973286ef19c10bf6326a6 Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 24 Aug 2011 01:55:34 -0700 Subject: turn off notifier - runaway --- include/diaspora.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 5ea38bad5..563eaa4e2 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -622,7 +622,7 @@ function diaspora_comment($importer,$xml,$msg) { } // notify others - proc_run('php','include/notifier.php','comment',$message_id); +// proc_run('php','include/notifier.php','comment',$message_id); return; @@ -846,7 +846,7 @@ EOT; } // notify others - proc_run('php','include/notifier.php','comment',$message_id); +// proc_run('php','include/notifier.php','comment',$message_id); return; } -- cgit v1.2.3 From a775474dff73e0e17e95bcfee42caeecdacf5295 Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 24 Aug 2011 04:42:28 -0700 Subject: cleaned up the conditions on when to and when not to relay. --- include/diaspora.php | 18 +++++++++++------- include/items.php | 2 +- include/notifier.php | 32 +++++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/diaspora.php b/include/diaspora.php index 563eaa4e2..75d47e05a 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -544,7 +544,6 @@ function diaspora_comment($importer,$xml,$msg) { if($parent_author_signature) { -// $owner_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $msg['author']; $owner_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $diaspora_handle; $parent_author_signature = base64_decode($parent_author_signature); @@ -619,13 +618,14 @@ function diaspora_comment($importer,$xml,$msg) { dbesc(base64_encode($author_signature)), dbesc($diaspora_handle) ); - } - // notify others -// proc_run('php','include/notifier.php','comment',$message_id); + // if the message isn't already being relayed, notify others + // the existence of parent_author_signature means the parent_author or owner + // is already relaying. + proc_run('php','include/notifier.php','comment',$message_id); + } return; - } function diaspora_photo($importer,$xml,$msg) { @@ -845,8 +845,12 @@ EOT; ); } - // notify others -// proc_run('php','include/notifier.php','comment',$message_id); + // if the message isn't already being relayed, notify others + // the existence of parent_author_signature means the parent_author or owner + // is already relaying. + + if(! $parent_author_signature) + proc_run('php','include/notifier.php','comment',$message_id); return; } diff --git a/include/items.php b/include/items.php index 746e3b294..19e56c0b6 100644 --- a/include/items.php +++ b/include/items.php @@ -1556,7 +1556,7 @@ function subscribe_to_hub($url,$importer,$contact) { intval($importer['uid']) ); } - if(! count($r)) + if((! count($r)) || $contact['network'] === NETWORK_DIASPORA) return; $push_url = get_config('system','url') . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id']; diff --git a/include/notifier.php b/include/notifier.php index 1c8245c7a..7b645844f 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -150,7 +150,37 @@ function notifier_run($argv, $argc){ $parent = $items[0]; - if($parent['wall'] == 0 && (! $expire)) { + // This is IMPORTANT!!!! + + // We will only send a "notify owner to relay" or followup message if the referenced post + // originated on our system by virtue of having our hostname somewhere + // in the URI, AND it was a comment (not top_level) AND the parent originated elsewhere. + // if $parent['wall'] == 1 we will already have the parent message in our array + // and we will relay the whole lot. + + // expire sends an entire group of expire messages and cannot be forwarded. + // However the conversation owner will be a part of the conversation and will + // be notified during this run. + // Other DFRN conversation members will be alerted during polled updates. + + // Diaspora members currently are not notified of expirations, and other networks have + // either limited or no ability to process deletions. We should at least fix Diaspora + // by stringing togther an array of retractions and sending them onward. + + + $localhost = $a->get_hostname(); + if(strpos($localhost,':')) + $localhost = substr($localhost,0,strpos($localhost,':')); + + /** + * + * Be VERY CAREFUL if you make any changes to the following line. Seemingly innocuous changes + * have been known to cause runaway conditions which affected several servers, along with + * permissions issues. + * + */ + + if((! $top_level) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) { // local followup to remote post $followup = true; $public_message = false; // not public -- cgit v1.2.3 From d6f9e0e2a4864a7e7de48f40c8da676c870db6bc Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 24 Aug 2011 05:58:31 -0700 Subject: change the way public feeds work just to fix statusnet's bug, because they won't --- include/items.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 19e56c0b6..150be2707 100644 --- a/include/items.php +++ b/include/items.php @@ -12,6 +12,18 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) if(! strlen($owner_nick)) killme(); + $public_feed = (($dfrn_id) ? false : true); + $starred = false; + $converse = false; + + if($public_feed && $a->argc > 2) { + for($x = 2; $x < $a->argc; $x++) { + if($a->argv[$x] == 'converse') + $converse = true; + } + } + + $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' "; $r = q("SELECT `contact`.*, `user`.`uid` AS `user_uid`, `user`.`nickname`, `user`.`timezone` @@ -29,7 +41,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) $birthday = feed_birthday($owner_id,$owner['timezone']); - if(strlen($dfrn_id)) { + if(! $public_feed) { $sql_extra = ''; switch($direction) { @@ -81,7 +93,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) ); } - if($dfrn_id === '' || $dfrn_id === '*') + if($public_feed) $sort = 'DESC'; else $sort = 'ASC'; @@ -89,6 +101,11 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) if(! strlen($last_update)) $last_update = 'now -30 days'; + if($public_feed) { + if(! $converse) + $sql_extra .= " AND `contact`.`self` = 1 "; + } + $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, @@ -152,7 +169,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) // public feeds get html, our own nodes use bbcode - if($dfrn_id === '') { + if($public_feed) { $type = 'html'; // catch any email that's in a public conversation and make sure it doesn't leak if($item['private']) -- cgit v1.2.3 From 8f6ae2b66044a36996ac92a8db1a540db9c71fe3 Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 24 Aug 2011 20:40:08 -0700 Subject: missing salmon key? report it. --- include/auth.php | 6 ++++-- include/queue.php | 5 +++-- include/salmon.php | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/auth.php b/include/auth.php index 768af626f..b7b96bdc0 100644 --- a/include/auth.php +++ b/include/auth.php @@ -48,7 +48,8 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p goaway(z_root()); } - $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", + $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` + FROM `user` WHERE `uid` = %d LIMIT 1", intval($_SESSION['uid']) ); @@ -183,7 +184,8 @@ else { // process normal login request - $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) + $r = q("SELECT `user`.*, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` + FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `password` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1", dbesc(trim($_POST['openid_url'])), dbesc(trim($_POST['openid_url'])), diff --git a/include/queue.php b/include/queue.php index da5028aee..fe96a75ce 100644 --- a/include/queue.php +++ b/include/queue.php @@ -83,7 +83,8 @@ function queue_run($argv, $argc){ continue; } - $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", + $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey` + FROM `user` WHERE `uid` = %d LIMIT 1", intval($c[0]['uid']) ); if(! count($u)) { @@ -124,7 +125,7 @@ function queue_run($argv, $argc){ case NETWORK_DIASPORA: if($contact['notify']) { logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name']); - $deliver_status = diaspora_transmit($owner,$contact['notify'],$data); + $deliver_status = diaspora_transmit($owner,$contact,$data); if($deliver_status == (-1)) update_queue_time($q_item['id']); diff --git a/include/salmon.php b/include/salmon.php index 4043b4f1d..ba61fffcc 100644 --- a/include/salmon.php +++ b/include/salmon.php @@ -73,6 +73,13 @@ function slapper($owner,$url,$slap) { if(! strlen($url)) return; + + if(! $owner['sprvkey']) { + logger(sprintf("slapper: user '%s' (%d) does not have a salmon private key. Send failed.", + $owner['username'],$owner['uid'])); + return; + } + // add all namespaces to item $namespaces = <<< EOT -- cgit v1.2.3 From 74d61ed00b9ff6fe768d4a0f4a27da246020c270 Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 24 Aug 2011 22:40:26 -0700 Subject: contact menu beginnings --- include/Contact.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'include') diff --git a/include/Contact.php b/include/Contact.php index 4ca77d065..6eda0b6c5 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -85,3 +85,55 @@ function unmark_for_death($contact) { ); }} +if(! function_exists('contact_photo_menu')){ +function contact_photo_menu($contact) { + + $a = get_app(); + + $contact_url=""; + $pm_url=""; + $status_link=""; + $photos_link=""; + $posts_link=""; + + $sparkle = false; + if($contact['network'] === NETWORK_DFRN) { + $sparkle = true; + $profile_link = $a->get_baseurl() . '/redir/' . $contact['id']; + } + else + $profile_link = $contact['url']; + + if($profile_link === 'mailbox') + $profile_link = ''; + + if($sparkle) { + $status_link = $profile_link . "?url=status"; + $photos_link = $profile_link . "?url=photos"; + $profile_link = $profile_link . "?url=profile"; + $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id']; + } + + $contact_url = $a->get_baseurl() . '/contacts/' . $cid; + $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid; + + $menu = Array( + t("View status") => $status_link, + t("View profile") => $profile_link, + t("View photos") => $photos_link, + t("View recent") => $posts_link, + t("Edit contact") => $contact_url, + t("Send PM") => $pm_url, + ); + + + $args = array('contact' => $contact, 'menu' => $menu); + + call_hooks('contact_photo_menu', $args); + + $o = ""; + foreach($menu as $k=>$v){ + if ($v!="") $o .= "
  • $k
  • \n"; + } + return $o; +}} -- cgit v1.2.3 From 71fc694c6715601f8d9cabcb1835c66a23aea4ca Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 24 Aug 2011 23:20:04 -0700 Subject: contact photo menu --- include/Contact.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/Contact.php b/include/Contact.php index 6eda0b6c5..7524c0cea 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -114,8 +114,8 @@ function contact_photo_menu($contact) { $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id']; } - $contact_url = $a->get_baseurl() . '/contacts/' . $cid; - $posts_link = $a->get_baseurl() . '/network/?cid=' . $cid; + $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id']; + $posts_link = $a->get_baseurl() . '/network/?cid=' . $contact['id']; $menu = Array( t("View status") => $status_link, -- cgit v1.2.3 From 1b33ba6587766d939ac37c1ca60aa5c012e4da9d Mon Sep 17 00:00:00 2001 From: Friendika Date: Thu, 25 Aug 2011 06:01:40 -0700 Subject: third attempt to get rid of this stupid warning --- include/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index f0dd828d1..691a8c9f9 100644 --- a/include/network.php +++ b/include/network.php @@ -536,7 +536,7 @@ function fetch_xrd_links($url) { $aliases = array($alias); else $aliases = $alias; - if($aliases && count($aliases)) { + if(is_array($aliases) && count($aliases)) { foreach($aliases as $alias) { $links[]['@attributes'] = array('rel' => 'alias' , 'href' => $alias); } -- cgit v1.2.3 From 21c03fb5220d2190a8a764d5430c6fa8bc013860 Mon Sep 17 00:00:00 2001 From: Friendika Date: Thu, 25 Aug 2011 16:37:27 -0700 Subject: diaspora2bb, salmon fix argument error --- include/bb2diaspora.php | 19 +++++++++++++++++ include/diaspora.php | 54 ++----------------------------------------------- include/salmon.php | 6 +++--- 3 files changed, 24 insertions(+), 55 deletions(-) (limited to 'include') diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 5ce34d666..7f7b8748d 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -5,6 +5,25 @@ require_once('include/event.php'); + +function diaspora2bb($s) { + + $s = str_replace(array('\\**','\\__','\\*','\\_'), array('-^doublestar^-','-^doublescore-^','-^star^-','-^score^-'),$s); + $s = preg_replace("/\*\*\*(.+?)\*\*\*/", '[b][i]$1[/i][/b]', $s); + $s = preg_replace("/\_\_\_(.+?)\_\_\_/", '[b][i]$1[/i][/b]', $s); + $s = preg_replace("/\*\*(.+?)\*\*/", '[b]$1[/b]', $s); + $s = preg_replace("/\_\_(.+?)\_\_/", '[b]$1[/b]', $s); + $s = preg_replace("/\*(.+?)\*/", '[i]$1[/i]', $s); + $s = preg_replace("/\_(.+?)\_/", '[i]$1[/i]', $s); + $s = str_replace(array('-^doublestar^-','-^doublescore-^','-^star^-','-^score^-'), array('**','__','*','_'), $s); + $s = preg_replace('/\[(.+?)\]\((.+?)\)/','[url=$2]$1[/url]',$s); + + $s = escape_tags($s); + return $s; + +} + + function stripdcode_br_cb($s) { return '[code]' . str_replace('
    ', '', $s[1]) . '[/code]'; } diff --git a/include/diaspora.php b/include/diaspora.php index 75d47e05a..90c802363 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -435,32 +435,7 @@ function diaspora_post($importer,$xml) { $created = unxmlify($xml->created_at); $private = ((unxmlify($xml->public) == 'false') ? 1 : 0); - $body = unxmlify($xml->raw_message); - - require_once('library/HTMLPurifier.auto.php'); - require_once('include/html2bbcode.php'); - - $maxlen = get_max_import_size(); - if($maxlen && (strlen($body) > $maxlen)) - $body = substr($body,0, $maxlen); - - if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) { - - $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', - '[youtube]$1[/youtube]', $body); - - $body = preg_replace('#].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?#s', - '[youtube]$1[/youtube]', $body); - - $body = oembed_html2bbcode($body); - - $config = HTMLPurifier_Config::createDefault(); - $config->set('Cache.DefinitionImpl', null); - $purifier = new HTMLPurifier($config); - $body = $purifier->purify($body); - - $body = html2bbcode($body); - } + $body = diaspora2bb($xml->raw_message); $datarray = array(); $datarray['uid'] = $importer['uid']; @@ -558,32 +533,7 @@ function diaspora_comment($importer,$xml,$msg) { // Phew! Everything checks out. Now create an item. - require_once('library/HTMLPurifier.auto.php'); - require_once('include/html2bbcode.php'); - - $body = $text; - - $maxlen = get_max_import_size(); - if($maxlen && (strlen($body) > $maxlen)) - $body = substr($body,0, $maxlen); - - if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) { - - $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', - '[youtube]$1[/youtube]', $body); - - $body = preg_replace('#].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?#s', - '[youtube]$1[/youtube]', $body); - - $body = oembed_html2bbcode($body); - - $config = HTMLPurifier_Config::createDefault(); - $config->set('Cache.DefinitionImpl', null); - $purifier = new HTMLPurifier($config); - $body = $purifier->purify($body); - - $body = html2bbcode($body); - } + $body = diaspora2bb($text); $message_id = $diaspora_handle . ':' . $guid; diff --git a/include/salmon.php b/include/salmon.php index ba61fffcc..9153f8994 100644 --- a/include/salmon.php +++ b/include/salmon.php @@ -109,11 +109,11 @@ EOT; $precomputed = '.YXBwbGljYXRpb24vYXRvbSt4bWw=.YmFzZTY0dXJs.UlNBLVNIQTI1Ng=='; - $signature = base64url_encode(rsa_sign(str_replace('=','',$data . $precomputed),true),$owner['sprvkey']); + $signature = base64url_encode(rsa_sign(str_replace('=','',$data . $precomputed),$owner['sprvkey'])); - $signature2 = base64url_encode(rsa_sign($data . $precomputed),$owner['sprvkey']); + $signature2 = base64url_encode(rsa_sign($data . $precomputed,$owner['sprvkey'])); - $signature3 = base64url_encode(rsa_sign($data),$owner['sprvkey']); + $signature3 = base64url_encode(rsa_sign($data,$owner['sprvkey'])); $salmon_tpl = get_markup_template('magicsig.tpl'); -- cgit v1.2.3 From 99ea045723b89a312db5227f0036c76d481e58a1 Mon Sep 17 00:00:00 2001 From: Friendika Date: Thu, 25 Aug 2011 18:12:42 -0700 Subject: some minor work on contact edit page --- include/contact_selectors.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/contact_selectors.php b/include/contact_selectors.php index ac1e38e4f..1303acf74 100644 --- a/include/contact_selectors.php +++ b/include/contact_selectors.php @@ -46,10 +46,11 @@ function contact_reputation($current) { } -function contact_poll_interval($current) { +function contact_poll_interval($current, $disabled = false) { + $dis = (($disabled) ? ' disabled="disabled" ' : ''); $o = ''; - $o .= '" . "\r\n"; $rep = array( 0 => t('Frequently'), @@ -67,3 +68,13 @@ function contact_poll_interval($current) { $o .= "\r\n"; return $o; } + + +function network_to_name($s) { + + call_hooks('network_to_name', $s); + + return str_replace(array(NETWORK_DFRN,NETWORK_OSTATUS,NETWORK_FEED,NETWORK_MAIL,NETWORK_DIASPORA,NETWORK_FACEBOOK,NETWORK_ZOT), + array(t('Friendika'),t('OStatus'),t('RSS/Atom'),t('Email'),t('Diaspora'),t('Facebook'),t('Zot!')),$s); + +} -- cgit v1.2.3 From 5eb08d43b6f78b1aec5f40d4a53725e713cfd9b5 Mon Sep 17 00:00:00 2001 From: Friendika Date: Thu, 25 Aug 2011 20:09:32 -0700 Subject: tweak to bbcode linkificator --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 3619015ca..6c26dabfe 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -41,7 +41,7 @@ function bbcode($Text,$preserve_nl = false) { // Perform URL Search - $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!\+\,]+)/", ' $2', $Text); + $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\%\$\!\+\,]+)/", ' $1$2', $Text); $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '$1', $Text); $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.*?)\[/url\])", '$2', $Text); -- cgit v1.2.3 From c15c53d307f1b298e6140e33dfbd859a68d0b5f9 Mon Sep 17 00:00:00 2001 From: Friendika Date: Thu, 25 Aug 2011 20:12:56 -0700 Subject: one more little tweak to linkificator --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 6c26dabfe..c05c36938 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -41,7 +41,7 @@ function bbcode($Text,$preserve_nl = false) { // Perform URL Search - $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\%\$\!\+\,]+)/", ' $1$2', $Text); + $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\%\$\!\+\,]+)/", '$1$2', $Text); $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '$1', $Text); $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.*?)\[/url\])", '$2', $Text); -- cgit v1.2.3 From a4739aef915c0083bc2020c66fe5361018259e00 Mon Sep 17 00:00:00 2001 From: Friendika Date: Thu, 25 Aug 2011 20:35:55 -0700 Subject: more logging diaspora pubdeliver --- include/notifier.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index 7b645844f..1acb6d71f 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -657,11 +657,18 @@ function notifier_run($argv, $argc){ break; case NETWORK_DIASPORA : require_once('include/diaspora.php'); - if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) + + logger('notifier: diaspora pubdelivery: ' . $contact['name']); + + if(get_config('system','dfrn_only') || (! get_config('system','diaspora_enabled')) || (! $normal_mode)) { + logger('notifier: diaspora pubdelivery not allowed at this time'); break; + } - if(! $contact['pubkey']) + if(! $contact['pubkey']) { + logger('notifier: diaspora pubdelivery: no pubkey'); break; + } if($target_item['verb'] === ACTIVITY_DISLIKE) { // unsupported -- cgit v1.2.3 From 1861dc1fae549a0ee2b6287d4f7dc7f8797f5070 Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 26 Aug 2011 01:32:22 -0700 Subject: don't allow fullscreen for youtube iframe - this makes it hard to visit the network page when they throw an error --- include/bbcode.php | 2 +- include/notifier.php | 8 ++++++-- include/queue.php | 28 +++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index c05c36938..a3f2971e5 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -134,7 +134,7 @@ function bbcode($Text,$preserve_nl = false) { // Youtube extensions $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); - $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); + $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); } // $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '', $Text); diff --git a/include/notifier.php b/include/notifier.php index 1acb6d71f..e92a4f6a8 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -641,15 +641,19 @@ function notifier_run($argv, $argc){ /* Don't deliver to folks who have already been delivered to */ - if(in_array($rr['id'],$conversants)) + if(in_array($rr['id'],$conversants)) { + logger('notifier: already delivered id=' . $rr['id']); continue; + } $n = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", - intval($rr['id']) + intval($rr['id']) ); if(count($n)) { $contact = $n[0]; + logger('pubdeliver: network: ' . $contact['network']); + switch($contact['network']) { case NETWORK_DFRN : logger('notifier: dfrnpubdelivery: ' . $contact['name']); diff --git a/include/queue.php b/include/queue.php index fe96a75ce..f1bcf2e9f 100644 --- a/include/queue.php +++ b/include/queue.php @@ -29,6 +29,11 @@ function queue_run($argv, $argc){ load_hooks(); + if($argc > 1) + $queue_id = intval($argv[1]); + else + $queue_id = 0; + $deadguys = array(); logger('queue: start'); @@ -44,13 +49,19 @@ function queue_run($argv, $argc){ q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); } - $r = q("SELECT `id` FROM `queue` WHERE `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE "); + if($queue_id) + $r = q("SELECT `id` FROM `queue` WHERE `id` = %d LIMIT 1", + intval($queue_id) + ); + else + $r = q("SELECT `id` FROM `queue` WHERE `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE "); if(! count($r)){ return; } - call_hooks('queue_predeliver', $a, $r); + if(! $queue_id) + call_hooks('queue_predeliver', $a, $r); // delivery loop @@ -63,9 +74,16 @@ function queue_run($argv, $argc){ // queue_predeliver hooks may have changed the queue db details, // so check again if this entry still needs processing - $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ", - intval($q_item['id']) - ); + if($queue_id) { + $qi = q("select * from queue where `id` = %d limit 1", + intval($queue_id) + ); + } + else { + $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ", + intval($q_item['id']) + ); + } if(! count($qi)) continue; -- cgit v1.2.3