From 61bbaeacde2761e97eeee8e5187b5a5f52f2c5c3 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 3 Dec 2014 15:17:56 -0500 Subject: [PATCH 1/8] adding tagging support --- src/indieweb/comments.php | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index afbe765..77ece7e 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -48,6 +48,7 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { 'url' => false ); $rsvp = null; + $tag = null; if(array_key_exists('type', $mf) && in_array('h-entry', $mf['type']) && array_key_exists('properties', $mf)) { $properties = $mf['properties']; @@ -99,6 +100,59 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { } } } + // If the post has an explicit tag-of property, verify it matches $refURL and set the type to "reply" + if($refURL && array_key_exists('tag-of', $properties)) { + // tag-of may be a string or an h-cite + foreach($properties['tag-of'] as $check) { + if(is_string($check) && $check == $refURL) { + $type = 'tag'; + continue; + } elseif(is_array($check)) { + if(array_key_exists('type', $check) && in_array('h-cite', $check['type'])) { + if(array_key_exists('properties', $check) && array_key_exists('url', $check['properties'])) { + if(in_array($refURL, $check['properties']['url'])) { + $type = 'tag'; + } + } + } + } + } + } + if($type=='tag'){ + foreach($properties['category'] as $check) { + if(is_string($check)){ + $tag=array('category' => $check); + } elseif(is_array($check)){ + $tag=array(); + if(array_key_exists('value', $check) && is_string($check['value'])) { + $tag['name'] = $check['value']; + } + if(array_key_exists('properties', $check) && is_array($check['properties'])){ + if(array_key_exists('name', $check['properties'])){ + if(is_string($check['properties']['name'])) { + $tag['name'] = $check['properties']['name']; + } elseif (is_array($check['properties']['name']) && is_string($check['properties']['name'][0])) { + $tag['name'] = $check['properties']['name'][0]; + } + } + if(array_key_exists('url', $check['properties'])){ + if(is_string($check['properties']['url'])) { + $tag['url'] = $check['properties']['url']; + } elseif (is_array($check['properties']['url']) && is_string($check['properties']['url'][0])) { + $tag['url'] = $check['properties']['url'][0]; + } + } + } + if(array_key_exists('shape', $check) && is_string($check['shape'])) { + $tag['shape'] = $check['shape']; + } + if(array_key_exists('coords', $check) && is_string($check['coords'])) { + $tag['coords'] = $check['coords']; + } + + } + } + } // Check if the reply is an RSVP if(array_key_exists('rsvp', $properties)) { @@ -213,6 +267,10 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { $result['rsvp'] = $rsvp; } + if($tag !== null) { + $result['tag'] = $tag; + } + return $result; } From 6e109b5e54d99865aaed774a269c2075b638920a Mon Sep 17 00:00:00 2001 From: BenRoberts Date: Fri, 20 Mar 2015 16:49:22 -0400 Subject: [PATCH 2/8] adding tagged as a type for when YOU are tagged in something --- src/indieweb/comments.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index ecf27e9..058aa9e 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -114,10 +114,11 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { } } } - // If the post has an explicit tag-of property, verify it matches $refURL and set the type to "reply" + // If the post has an explicit tag-of property, verify it matches $refURL and set the type to "tag" if($refURL && array_key_exists('tag-of', $properties)) { // tag-of may be a string or an h-cite foreach($properties['tag-of'] as $check) { + removeScheme($check); if(is_string($check) && $check == $refURL) { $type = 'tag'; continue; @@ -131,6 +132,29 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { } } } + //this could be something you are actually tagged in + if($type != 'tag'){ + foreach($properties['category'] as $check){ + if(isset($check['type']) && in_array('h-card', $check['type'])) { + if(array_key_exists('properties', $check) && array_key_exists('url', $check['properties'])){ + + foreach( $check['properties']['url'] as $test_url){ + removeScheme($test_url); + if(is_string($test_url) && $test_url == $refURL) { + $type = 'tagged'; + continue; + } + } + + } + } + if(is_array($cat)){ + foreach($cat as $check){ + } + } + } + + } } if($type=='tag'){ foreach($properties['category'] as $check) { @@ -163,7 +187,6 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { if(array_key_exists('coords', $check) && is_string($check['coords'])) { $tag['coords'] = $check['coords']; } - } } } @@ -289,7 +312,7 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { // If this is a "mention" instead of a "reply", and if there is no "content" property, // then we actually want to use the "name" property as the name and leave "text" blank. - if($type == 'mention' && !array_key_exists('content', $properties)) { + if(($type == 'mention' || $type == 'tagged') && !array_key_exists('content', $properties)) { $name = $properties['name'][0]; $text = false; } else { From 98e4d2106efb086974be9dcdef044bdca6bd237a Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Fri, 3 Apr 2015 09:39:59 -0400 Subject: [PATCH 3/8] allow for multiple tags --- src/indieweb/comments.php | 70 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index 058aa9e..91f8fdb 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -157,38 +157,40 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { } } if($type=='tag'){ - foreach($properties['category'] as $check) { - if(is_string($check)){ - $tag=array('category' => $check); - } elseif(is_array($check)){ - $tag=array(); - if(array_key_exists('value', $check) && is_string($check['value'])) { - $tag['name'] = $check['value']; - } - if(array_key_exists('properties', $check) && is_array($check['properties'])){ - if(array_key_exists('name', $check['properties'])){ - if(is_string($check['properties']['name'])) { - $tag['name'] = $check['properties']['name']; - } elseif (is_array($check['properties']['name']) && is_string($check['properties']['name'][0])) { - $tag['name'] = $check['properties']['name'][0]; - } - } - if(array_key_exists('url', $check['properties'])){ - if(is_string($check['properties']['url'])) { - $tag['url'] = $check['properties']['url']; - } elseif (is_array($check['properties']['url']) && is_string($check['properties']['url'][0])) { - $tag['url'] = $check['properties']['url'][0]; - } - } - } - if(array_key_exists('shape', $check) && is_string($check['shape'])) { - $tag['shape'] = $check['shape']; - } - if(array_key_exists('coords', $check) && is_string($check['coords'])) { - $tag['coords'] = $check['coords']; - } - } - } + $tags = array(); + foreach($properties['category'] as $check) { + if(is_string($check)){ + $tag=array('category' => $check); + } elseif(is_array($check)){ + $tag=array(); + if(array_key_exists('value', $check) && is_string($check['value'])) { + $tag['name'] = $check['value']; + } + if(array_key_exists('properties', $check) && is_array($check['properties'])){ + if(array_key_exists('name', $check['properties'])){ + if(is_string($check['properties']['name'])) { + $tag['name'] = $check['properties']['name']; + } elseif (is_array($check['properties']['name']) && is_string($check['properties']['name'][0])) { + $tag['name'] = $check['properties']['name'][0]; + } + } + if(array_key_exists('url', $check['properties'])){ + if(is_string($check['properties']['url'])) { + $tag['url'] = $check['properties']['url']; + } elseif (is_array($check['properties']['url']) && is_string($check['properties']['url'][0])) { + $tag['url'] = $check['properties']['url'][0]; + } + } + } + if(array_key_exists('shape', $check) && is_string($check['shape'])) { + $tag['shape'] = $check['shape']; + } + if(array_key_exists('coords', $check) && is_string($check['coords'])) { + $tag['coords'] = $check['coords']; + } + } + $tags[] = $tag; + } } // Check if the reply is an RSVP @@ -345,8 +347,8 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { $result['rsvp'] = $rsvp; } - if($tag !== null) { - $result['tag'] = $tag; + if($tags !== null) { + $result['tags'] = $tags; } return $result; From 3a77e03d041c7bcdcbb2d8756b45051243cfa140 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Tue, 7 Apr 2015 10:19:33 -0400 Subject: [PATCH 4/8] adding return of syndicated copies to make deduplication much easier --- src/indieweb/comments.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index 91f8fdb..1fe9cf9 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -94,6 +94,12 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { if(array_key_exists('url', $properties)) { $url = $properties['url'][0]; } + if(array_key_exists('syndication', $properties)) { + $syndications = array(); + foreach($properties['syndication'] as $syndication_link){ + $syndications[] = $syndication_link; + } + } // If the post has an explicit in-reply-to property, verify it matches $refURL and set the type to "reply" if($refURL && array_key_exists('in-reply-to', $properties)) { @@ -337,6 +343,7 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { 'name' => $name, 'text' => $text, 'url' => $url, + 'syndications' => $syndications, 'type' => $type ); From 4a64a9eac96f7053a02bc649b8d4450fd47cb6f8 Mon Sep 17 00:00:00 2001 From: BenRoberts Date: Tue, 7 Apr 2015 20:40:40 -0400 Subject: [PATCH 5/8] fix values not being by default --- src/indieweb/comments.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index 1fe9cf9..3832ebb 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -61,7 +61,8 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { 'url' => false ); $rsvp = null; - $tag = null; + $tags = null; + $syndications = null; if(array_key_exists('type', $mf) && in_array('h-entry', $mf['type']) && array_key_exists('properties', $mf)) { $properties = $mf['properties']; @@ -343,7 +344,6 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { 'name' => $name, 'text' => $text, 'url' => $url, - 'syndications' => $syndications, 'type' => $type ); @@ -358,6 +358,10 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { $result['tags'] = $tags; } + if($syndications !== null) { + $result['syndications'] = $syndications; + } + return $result; } From bbff0479660af7ce80ca0f4914b43132c5d06ef1 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Thu, 17 Sep 2015 22:26:17 -0400 Subject: [PATCH 6/8] record comments on comments --- src/indieweb/comments.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index 3832ebb..a6256a9 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -60,6 +60,7 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { 'photo' => false, 'url' => false ); + $comments = array(); $rsvp = null; $tags = null; $syndications = null; @@ -95,6 +96,13 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { if(array_key_exists('url', $properties)) { $url = $properties['url'][0]; } + + if(array_key_exists('comment', $properties)) { + foreach($properties['comment'] as $comment) { + $comments[] = $this->parse($comment, $url, $maxTextLength, $maxLines); // recurse for all comments + } + } + if(array_key_exists('syndication', $properties)) { $syndications = array(); foreach($properties['syndication'] as $syndication_link){ @@ -347,21 +355,23 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { 'type' => $type ); + if(!empty($syndications)){ + $result['syndications'] = $syndications; + } if($type == 'invite') $result['invitee'] = $invitee; if($rsvp !== null) { $result['rsvp'] = $rsvp; } + if(!empty($comments)) { + $result['comments'] = $comments; + } if($tags !== null) { $result['tags'] = $tags; } - if($syndications !== null) { - $result['syndications'] = $syndications; - } - return $result; } From 8772dd7d406a27731774b72d0ca96a88d78245f4 Mon Sep 17 00:00:00 2001 From: BenRoberts Date: Thu, 15 Oct 2015 21:19:55 -0400 Subject: [PATCH 7/8] comments parsing now working --- src/indieweb/comments.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index c8f876b..95d687f 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -74,7 +74,7 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { $tags = null; $syndications = null; - if(array_key_exists('type', $mf) && in_array('h-entry', $mf['type']) && array_key_exists('properties', $mf)) { + if ( array_key_exists('type', $mf) && (in_array('h-entry', $mf['type']) || in_array('h-cite', $mf['type'])) && array_key_exists('properties', $mf)) { $properties = $mf['properties']; if(array_key_exists('author', $properties)) { @@ -108,7 +108,7 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { if(array_key_exists('comment', $properties)) { foreach($properties['comment'] as $comment) { - $comments[] = $this->parse($comment, $url, $maxTextLength, $maxLines); // recurse for all comments + $comments[] = parse($comment, $url, $maxTextLength, $maxLines); // recurse for all comments } } From 176424d1822810decf88d447f8725bd6b08d21ec Mon Sep 17 00:00:00 2001 From: BenRoberts Date: Wed, 16 Dec 2015 20:02:34 -0500 Subject: [PATCH 8/8] reply should override a 'like', needed for reacji --- src/indieweb/comments.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index 95d687f..a170f67 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -119,6 +119,20 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { } } + // Check if this post is a "like-of" + if($refURL && array_key_exists('like-of', $properties)) { + collectURLs($properties['like-of']); + if(in_array($refURL, $properties['like-of'])) + $type = 'like'; + } + + // Check if this post is a "like" (Should be deprecated in the future) + if($refURL && array_key_exists('like', $properties)) { + collectURLs($properties['like']); + if(in_array($refURL, $properties['like'])) + $type = 'like'; + } + // If the post has an explicit in-reply-to property, verify it matches $refURL and set the type to "reply" if($refURL && array_key_exists('in-reply-to', $properties)) { // in-reply-to may be a string or an h-cite @@ -260,20 +274,6 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { $type = 'repost'; } - // Check if this post is a "like-of" - if($refURL && array_key_exists('like-of', $properties)) { - collectURLs($properties['like-of']); - if(in_array($refURL, $properties['like-of'])) - $type = 'like'; - } - - // Check if this post is a "like" (Should be deprecated in the future) - if($refURL && array_key_exists('like', $properties)) { - collectURLs($properties['like']); - if(in_array($refURL, $properties['like'])) - $type = 'like'; - } - // From http://indiewebcamp.com/comments-presentation#How_to_display // If the entry has an e-content, and if the content is not too long, use that