diff --git a/src/indieweb/comments.php b/src/indieweb/comments.php index 1a56572..72c290b 100644 --- a/src/indieweb/comments.php +++ b/src/indieweb/comments.php @@ -151,31 +151,26 @@ function parse($mf, $refURL=false, $maxTextLength=150, $maxLines=2) { } // Check if this post is a "repost" - if($refURL && array_key_exists('repost-of', $properties)) { - collectURLs($properties['repost-of']); - if(in_array($refURL, $properties['repost-of'])) - $type = 'repost'; - } - // Also check for "u-repost" since some people are sending that. Probably "u-repost-of" will win out. - if($refURL && array_key_exists('repost', $properties)) { - collectURLs($properties['repost']); - if(in_array($refURL, $properties['repost'])) - $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'; + foreach(array('repost-of', 'u-repost-of', 'u-repost', 'repost') as $repost) { + if($refURL && array_key_exists($repost, $properties)) { + collectURLs($properties[$repost]); + if(in_array($refURL, $properties[$repost])) + $type = 'repost'; + break; + } } - // 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'; + // Check if this post is a "like" + // Prefer "like-of" but also check for "u-lile-of", "u-like" and "like" (should be deprecated in the future) + foreach(array('like-of', 'u-like-of', 'u-like', 'like') as $like) { + if($refURL && array_key_exists($like, $properties)) { + collectURLs($properties[$like]); + if(in_array($refURL, $properties[$like])) { + $type = 'like'; + break; + } + } } // From http://indiewebcamp.com/comments-presentation#How_to_display diff --git a/tests/BasicTest.php b/tests/BasicTest.php index 9dfb354..7e01093 100644 --- a/tests/BasicTest.php +++ b/tests/BasicTest.php @@ -20,7 +20,7 @@ private function buildHEntry($input, $author=false, $replyTo=true) { 'photo' => array('http://aaronparecki.com/images/aaronpk.png') ) )) - ), + ), 'published' => array('2014-02-16T18:48:17-0800'), 'url' => array('http://aaronparecki.com/post/1'), ) @@ -29,7 +29,7 @@ private function buildHEntry($input, $author=false, $replyTo=true) { $entry['properties']['in-reply-to'] = array($this->_refURL); } if(is_array($replyTo)) { - $entry['properties']['in-reply-to'] = array($replyTo); + $entry['properties']['in-reply-to'] = array($replyTo); } if(array_key_exists('content', $input)) { if(is_string($input['content'])) { @@ -51,8 +51,8 @@ private function buildHEntry($input, $author=false, $replyTo=true) { public function testBasicExample() { $result = IndieWeb\comments\parse($this->buildHEntry(array( - 'name' => 'post name', - 'summary' => 'post summary', + 'name' => 'post name', + 'summary' => 'post summary', 'content' => 'this is some content' )), $this->_refURL, 90); $this->assertEquals(array( @@ -71,8 +71,8 @@ public function testBasicExample() { public function testContentTooLongSummaryIsOk() { $result = IndieWeb\comments\parse($this->buildHEntry(array( - 'name' => 'post name', - 'summary' => 'post summary', + 'name' => 'post name', + 'summary' => 'post summary', 'content' => '

this is some content but it is longer than 90 characters so the summary will be used instead

' )), $this->_refURL, 90); $this->assertEquals('reply', $result['type']); @@ -81,8 +81,8 @@ public function testContentTooLongSummaryIsOk() { public function testContentTooLongSummaryTooLong() { $result = IndieWeb\comments\parse($this->buildHEntry(array( - 'name' => 'post name', - 'summary' => 'in this case the post summary is also too long, so a truncated version should be displayed instead', + 'name' => 'post name', + 'summary' => 'in this case the post summary is also too long, so a truncated version should be displayed instead', 'content' => '

this is some content but it is longer than 90 characters so the summary will be used instead

' )), $this->_refURL, 90); $this->assertEquals('reply', $result['type']); @@ -91,7 +91,7 @@ public function testContentTooLongSummaryTooLong() { public function testContentTooLongNoSummary() { $result = IndieWeb\comments\parse($this->buildHEntry(array( - 'name' => 'post name', + 'name' => 'post name', 'content' => '

this is some content but it is longer than 90 characters so it will be truncated because there is no summary

' )), $this->_refURL, 90); $this->assertEquals('reply', $result['type']); @@ -228,13 +228,13 @@ public function testMultiLineCommentFitsWithinLimits() { public function testTrimMultiLineCommentHalfWayThroughThirdLine() { $result = IndieWeb\comments\parse($this->buildHEntry(array( 'content' => array( - 'html' => '#HouseOfCards s2e1 was good. + 'html' => '#HouseOfCards s2e1 was good. But the best thing yesterday was getting to try a Boosted electric skateboard: http://boostedboards.com/ Amazing. Handheld trigger remote control via Bluetooth. Forward and reverse. And I only tried it in "turtle" mode. In "rabbit" mode it can apparently do 20 miles an hour. Up hill. Jetsons-like motor sound included. Forget about Segway, Boosted's electric skateboard feels like an object from the future dropped into the present, more in the realm of Marty's hoverboard (Back To The Future II & III) and Y.T.'s Smartwheels skateboard (Snow Crash).', - 'value' => "#HouseOfCards s2e1 was good. + 'value' => "#HouseOfCards s2e1 was good. But the best thing yesterday was getting to try a Boosted electric skateboard: http://boostedboards.com/ Amazing. Handheld trigger remote control via Bluetooth. Forward and reverse. And I only tried it in \"turtle\" mode. In \"rabbit\" mode it can apparently do 20 miles an hour. Up hill. Jetsons-like motor sound included. @@ -244,7 +244,7 @@ public function testTrimMultiLineCommentHalfWayThroughThirdLine() { ), false, false), $this->_refURL, 197, 3); $this->assertEquals('mention', $result['type']); $this->assertEquals('', $result['name']); - $this->assertEquals("#HouseOfCards s2e1 was good. + $this->assertEquals("#HouseOfCards s2e1 was good. But the best thing yesterday was getting to try a Boosted electric skateboard: http://boostedboards.com/ Amazing. Handheld trigger remote control via Bluetooth. ...", $result['text']); @@ -316,6 +316,26 @@ public function testIsLikeOf() { $this->assertEquals('liked this post', $result['text']); } + public function testIsULikeOf() { + $result = IndieWeb\comments\parse($this->buildHEntry(array( + 'name' => 'Liked this', + 'content' => 'liked this post', + 'u-like-of' => $this->_refURL + )), $this->_refURL, 200); + $this->assertEquals('like', $result['type']); + $this->assertEquals('liked this post', $result['text']); + } + + public function testIsULike() { + $result = IndieWeb\comments\parse($this->buildHEntry(array( + 'name' => 'Liked this', + 'content' => 'liked this post', + 'u-like' => $this->_refURL + )), $this->_refURL, 200); + $this->assertEquals('like', $result['type']); + $this->assertEquals('liked this post', $result['text']); + } + public function testIsRepostOf() { $result = IndieWeb\comments\parse($this->buildHEntry(array( 'name' => 'Reposted this', @@ -326,6 +346,26 @@ public function testIsRepostOf() { $this->assertEquals('Reposted this', $result['text']); } + public function testIsURepostOf() { + $result = IndieWeb\comments\parse($this->buildHEntry(array( + 'name' => 'Reposted this', + 'content' => 'Reposted this', + 'u-repost-of' => $this->_refURL + )), $this->_refURL, 200); + $this->assertEquals('repost', $result['type']); + $this->assertEquals('Reposted this', $result['text']); + } + + public function testIsURepost() { + $result = IndieWeb\comments\parse($this->buildHEntry(array( + 'name' => 'Reposted this', + 'content' => 'Reposted this', + 'u-repost' => $this->_refURL + )), $this->_refURL, 200); + $this->assertEquals('repost', $result['type']); + $this->assertEquals('Reposted this', $result['text']); + } + public function testIsRepost() { $result = IndieWeb\comments\parse($this->buildHEntry(array( 'name' => 'Reposted this', @@ -366,8 +406,8 @@ public function testIsLikeOfHCite() { public function testAuthorIsURL() { $result = IndieWeb\comments\parse($this->buildHEntry(array( - 'name' => 'post name', - 'summary' => 'post summary', + 'name' => 'post name', + 'summary' => 'post summary', 'content' => '

this is some content

' ), 'http://aaronparecki.com/'), $this->_refURL, 200); $author = $result['author']; @@ -379,8 +419,8 @@ public function testAuthorIsURL() { public function testAuthorIsHCard() { $result = IndieWeb\comments\parse($this->buildHEntry(array( - 'name' => 'post name', - 'summary' => 'post summary', + 'name' => 'post name', + 'summary' => 'post summary', 'content' => '

this is some content

' )), $this->_refURL, 200); $author = $result['author']; @@ -392,8 +432,8 @@ public function testAuthorIsHCard() { public function testAuthorIsHCardWithNoPhoto() { $result = IndieWeb\comments\parse($this->buildHEntry(array( - 'name' => 'post name', - 'summary' => 'post summary', + 'name' => 'post name', + 'summary' => 'post summary', 'content' => '

this is some content

' ), array( 'type' => array('h-card'),