From f70a0b028288fa13c64f1ffaa310765a95347dac Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 8 Feb 2011 18:44:30 -0800 Subject: more graceful handling of some statusnet followups --- include/items.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index cffd13a01..b5bdd7833 100644 --- a/include/items.php +++ b/include/items.php @@ -1128,15 +1128,16 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) { } if(($is_reply) && is_array($contact)) { - + // Have we seen it? If not, import it. $item_id = $item->get_id(); - + $r = q("SELECT `uid`, `last-child`, `edited` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['uid']) ); + // FIXME update content if 'updated' changes if(count($r)) { $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow'); @@ -1155,6 +1156,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) { } continue; } + $datarray = get_atom_elements($feed,$item); $force_parent = false; if($contact['network'] === 'stat') { -- cgit v1.2.3 From 6b8bbef6c795fcf73c7c7271decf0f0bfed158c7 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 8 Feb 2011 20:55:34 -0800 Subject: suppress parse warnings --- include/oembed.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/oembed.php b/include/oembed.php index 37923a877..4d6b0af16 100644 --- a/include/oembed.php +++ b/include/oembed.php @@ -79,7 +79,10 @@ function oe_get_inner_html( $node ) { * and replace it with [embed]url[/embed] */ function oembed_html2bbcode($text) { - $dom = DOMDocument::loadHTML($text); + // If it doesn't parse at all, just return the text. + $dom = @DOMDocument::loadHTML($text); + if(! $dom) + return $text; $xpath = new DOMXPath($dom); $attr = "oembed"; -- cgit v1.2.3 From 5899ae9017c351b9987868871605f3f2324c62c0 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 8 Feb 2011 21:26:28 -0800 Subject: Support bbcode size tag - I may regret this... --- include/bbcode.php | 4 ++-- include/html2bbcode.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index eb0806dc5..f39ebd5b9 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -49,10 +49,10 @@ function bbcode($Text) { $Text = preg_replace("(\[o\](.+?)\[\/o\])is",'$1',$Text); // Check for colored text - $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","$2",$Text); + $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","$2",$Text); // Check for sized text - $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","$2",$Text); + $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","$2",$Text); // Check for list text $Text = preg_replace("/\[list\](.+?)\[\/list\]/is", '
    $1
' ,$Text); diff --git a/include/html2bbcode.php b/include/html2bbcode.php index 6af8df824..bde761f2f 100644 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -26,6 +26,7 @@ function html2bbcode($s) { '/\(.*?)\<\/a\>/is', '/\(.*?)\<\/code\>/is', '/\(.*?)\<\/span\>/is', + '/\(.*?)\<\/span\>/is', '/\(.*?)\<\/blockquote\>/is', '/\(.*?)\<\/video\>/is', '/\(.*?)\<\/audio\>/is', @@ -51,6 +52,7 @@ function html2bbcode($s) { '[url=$2]$4[/url]', '[code]$1[/code]', '[color="$1"]$2[/color]', + '[size=$1]$2[/size]', '[quote]$1[/quote]', '[video]$1[/video]', '[audio]$1[/audio]', -- cgit v1.2.3 From 971b16ea4aadf8a24427907619e482e4cafe6faa Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 9 Feb 2011 16:55:31 -0800 Subject: Accept pretty much bloody anything inside a [url] tag as a legal URL. --- include/bbcode.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index f39ebd5b9..c55ebab00 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -15,14 +15,14 @@ function bbcode($Text) { $Text = nl2br($Text); // Set up the parameters for a URL search string - $URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%"; + $URLSearchString = "^\[\]"; // Set up the parameters for a MAIL search string - $MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@"; + $MAILSearchString = $URLSearchString; // Perform URL Search - $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%]+)/", ' $2', $Text); + $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!]+)/", ' $2', $Text); $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '$1', $Text); $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '$2', $Text); -- cgit v1.2.3 From 05c52ae81da6ce3c3b57672c2560072e1ce2705c Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 9 Feb 2011 17:51:05 -0800 Subject: preserve newlines inside
 tags when importing feeds

---
 include/html2bbcode.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

(limited to 'include')

diff --git a/include/html2bbcode.php b/include/html2bbcode.php
index bde761f2f..734282d95 100644
--- a/include/html2bbcode.php
+++ b/include/html2bbcode.php
@@ -7,10 +7,15 @@
 
 function html2bbcode($s) {
 
+
+	// only keep newlines from source that are within pre tags
+
+	$s = stripnl_exceptinpre($s);
+
+
 	// Tags to Find
 
 	$htmltags = array(
-		'/\n/is',
 		'/\(.*?)\<\/pre\>/is',
 		'/\/is',
 		'/\<\/p\>/is',
@@ -36,7 +41,6 @@ function html2bbcode($s) {
 	// Replace with
 
 	$bbtags = array(
-		'',
 		'[code]$1[/code]',
 		'',
 		"\n",
@@ -66,5 +70,48 @@ function html2bbcode($s) {
 	// Strip all other HTML tags
 	$text = strip_tags($text);
 	return $text;
+
+}
+
+function stripnl_exceptinpre($string)
+{
+    // First, check for 
 tag
+    if(strpos($string, '
') === false)
+    {
+        return str_replace("\n","", $string);
+    }
+
+    // If there is a 
, we have to split by line
+    // and manually replace the linebreaks
+
+    $strArr=explode("\n", $string);
+
+    $output="";
+    $preFound=false;
+
+    // Loop over each line
+    foreach($strArr as $line)
+    {    // See if the line has a 
. If it does, set $preFound to true
+        if(strpos($line, "
") !== false)
+        {
+            $preFound=true;
+        }
+        elseif(strpos($line, "
") !== false) + { + $preFound=false; + } + + // If we are in a pre tag, add line and also add \n, else add the line without \n + if($preFound) + { + $output .= $line . "\n"; + } + else + { + $output .= $line ; + } + } + + return $output; } -- cgit v1.2.3 From de2c9531db2332f0c0e944add6f9d85e88476dff Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 9 Feb 2011 19:39:49 -0800 Subject: post permission hooks --- include/acl_selectors.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include') diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 269dc3e34..953243a43 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -3,6 +3,8 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) { + $a = get_app(); + $o = ''; $o .= "\r\n"; + call_hooks($a->module . '_post_' . $selname, $o); + return $o; } @@ -60,6 +71,15 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p intval(local_user()) ); + + $arr = array('contact' => $r, 'entry' => $o); + + // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow' + + call_hooks($a->module . '_pre_' . $selname, $arr); + + + if(count($r)) { foreach($r as $rr) { if((is_array($preselected)) && in_array($rr['id'], $preselected)) @@ -73,8 +93,10 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p } } + $o .= "\r\n"; + call_hooks($a->module . '_post_' . $selname, $o); return $o; } -- cgit v1.2.3 From 0bfe63e7d887f484c5cc0aea37ead0c283967fee Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 11 Feb 2011 03:17:16 -0800 Subject: reinstate send slaps but only at the top level (and followup) --- include/notifier.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/notifier.php b/include/notifier.php index b6c4ca571..648a07062 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -40,6 +40,7 @@ function notifier_run($argv, $argc){ break; } + $top_level = false; $recipients = array(); $url_recipients = array(); @@ -79,12 +80,16 @@ function notifier_run($argv, $argc){ return; } + // avoid race condition with deleting entries if($items[0]['deleted']) { foreach($items as $item) $item['deleted'] = 1; } + + if(count($items) == 1 && $items[0]['uri'] === $items[0]['parent-uri']) + $top_level = true; } $r = q("SELECT `contact`.*, `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags` @@ -167,9 +172,6 @@ function notifier_run($argv, $argc){ $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0"); -// if( ! count($r)){ -// return; -// } if(count($r)) $contacts = $r; @@ -242,12 +244,8 @@ function notifier_run($argv, $argc){ $atom .= atom_entry($item,'text',$contact,$owner,true); - // There's a problem here - we *were* going to use salmon to provide semi-authenticated - // communication to OStatus, but unless we're the item author they won't verify. - // commented out for now, though we'll still send local replies (and any mentions - // that they contain) upstream. Rethinking the problem space. - -// $slaps[] = atom_entry($item,'html',$contact,$owner,true); + if(($top_level) && ($notify_hub) && ($item['author-link'] === $item['owner-link'])) + $slaps[] = atom_entry($item,'html',$contact,$owner,true); } } } @@ -255,7 +253,7 @@ function notifier_run($argv, $argc){ logger('notifier: ' . $atom, LOGGER_DATA); -// logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA); + logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA); if($followup) $recip_str = $parent['contact-id']; -- cgit v1.2.3