From e3a0358f03d9aadc6c6a466ba3e51d48550f8246 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Wed, 29 Jun 2022 18:55:25 -0700 Subject: [PATCH 1/4] Update /validate-h-card --- composer.lock | 16 ++-- templates/validate-h-card.html.php | 119 ++++++++++++++++------------- web/index.php | 73 +++++++++++++++++- 3 files changed, 147 insertions(+), 61 deletions(-) diff --git a/composer.lock b/composer.lock index a619d86..51f017c 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/barnabywalters/php-mf-cleaner.git", - "reference": "e70b7b9a74b734527aa7e62d36fdbf3607559ad5" + "reference": "71566ebb40023d652f374eb80f9bd9c4c7d34cd6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barnabywalters/php-mf-cleaner/zipball/e70b7b9a74b734527aa7e62d36fdbf3607559ad5", - "reference": "e70b7b9a74b734527aa7e62d36fdbf3607559ad5", + "url": "https://api.github.com/repos/barnabywalters/php-mf-cleaner/zipball/71566ebb40023d652f374eb80f9bd9c4c7d34cd6", + "reference": "71566ebb40023d652f374eb80f9bd9c4c7d34cd6", "shasum": "" }, "require-dev": { @@ -27,6 +27,7 @@ "suggest": { "mf2/mf2": "To parse microformats2 structures from (X)HTML" }, + "default-branch": true, "type": "library", "autoload": { "files": [ @@ -44,7 +45,11 @@ } ], "description": "Cleans up microformats2 array structures", - "time": "2018-11-14T20:44:19+00:00" + "support": { + "issues": "https://github.com/barnabywalters/php-mf-cleaner/issues", + "source": "https://github.com/barnabywalters/php-mf-cleaner/tree/master" + }, + "time": "2022-06-28T17:28:22+00:00" }, { "name": "ezyang/htmlpurifier", @@ -2021,5 +2026,6 @@ "prefer-stable": false, "prefer-lowest": false, "platform": [], - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "2.3.0" } diff --git a/templates/validate-h-card.html.php b/templates/validate-h-card.html.php index 8db4e7b..55f099c 100644 --- a/templates/validate-h-card.html.php +++ b/templates/validate-h-card.html.php @@ -1,4 +1,5 @@ 'Anniversary', ]; + # default h-card to show properties for + $hCard = null; ?> +
-

Publishing on the IndieWeb Level 2

+

Publishing on the IndieWeb Level 2

-

1. Mark up your content (Profile, Notes, Articles, etc…) with microformats2

+

1. Mark up your content (Profile, Notes, Articles, etc…) with microformats2

-

Other humans can already understand your profile information and the things you post on your site. By adding a few simple class names to your HTML, other people’s software can understand it and use it for things like reply contexts, cross-site comments, event RSVPs, and more.

+

Other humans can already understand your profile information and the things you post on your site. By adding a few simple class names to your HTML, other people’s software can understand it and use it for things like reply contexts, cross-site comments, event RSVPs, and more.

-

Check your homepage h-card:

+

Check your homepage h-card:

-
-
- -
-
- + + +
+ +
+
+ +
+ + + +
+

Something Went Wrong!

+

When fetching , we got this problem:

+

- - - -
- -

Something Went Wrong!

-

When fetching , we got this problem:

-

+ + + +
+ + + +

Success!

+

This representative h-card was found on your site:

+ + 0): $hCard = $allHCards[0]; ?> + +

Almost there!

+

Multiple h-cards were found on your site! Consider only having one and marking it up as the representative h-card.

+

To identify the h-card that represents the page, you can:

+
    +
  • Add class="u-url u-uid" on the h-card’s link to
  • +
  • Or: add class="u-url" rel="me" on the h-card’s link to
  • +
+

Here is the first h-card found:

+ - -

Success!

-

This representative h-card was found on your site:

- 1): $hCard = $representativeHCards[0] ?> -

Almost there!

-

Multiple representative h-cards were found on your site! Consider only having one. Here’s the first one:

- -

Almost there!

-

An h-card was found on your site, but it’s not marked up as the representative h-card!

-

To identify the h-card that represents the page, you can:

-
    -
  • Add class="u-url u-uid" on the h-card's link to
  • -
  • Or: add class="u-url" rel="me" on the h-card's link to
  • -
- -

No h-cards found

-

No h-cards were found on your site! Adding one can be as simple as this:

-
<a class="h-card" rel="me" href="">Your Name</a>
+

No h-cards found

+

No h-cards were found on your site! Adding one can be as simple as this:

+ +
<a href="" class="h-card" rel="me">Your Name</a>
-

But you can also add other properties for a more detailed profile — see h-card on the microformats wiki for a full list.

- +

You can also add other properties for a more detailed profile — see h-card on the microformats wiki for a full list.

- + + +
@@ -104,22 +117,22 @@

URL

- +
    - +
-

Add your URLs! <a rel="me" class="u-url">…</a>

+

Add your URLs! <a rel="me" class="u-url">…</a>

- +

Email

    - +
@@ -130,7 +143,7 @@

-

Got a brief bio like a Twitter/Instagram bio? Add it to your own h-card as a note property! <p class="p-note">…</p>

+

Got a brief bio like a Twitter/Instagram bio? Add it to your own h-card as a note property! <p class="p-note">…</p>

@@ -146,17 +159,16 @@ } ?> -

See the full list of h-card properties.

- +

See the full list of h-card properties.

- - - $url)) ?> -
- - Want to be able to use h-card data in your code? Check out the open-source implementations. + $url)) ?> + +
+ + + Want to be able to use h-card data in your code? Check out the open-source implementations.
@@ -165,3 +177,4 @@
+ diff --git a/web/index.php b/web/index.php index 0022773..a39c703 100644 --- a/web/index.php +++ b/web/index.php @@ -2,6 +2,9 @@ namespace Indieweb\IndiewebifyMe; +error_reporting(E_ALL); +ini_set('display_errors', '1'); + ob_start(); require __DIR__ . '/../vendor/autoload.php'; ob_end_clean(); @@ -143,7 +146,7 @@ function datetimeProblem($datetimeStr) { $app = new Silex\Application(); $app->get('/', function () { - return render('index.html', array('composite_view' => true)); + return render('index.html', array('composite_view' => true, 'showResult' => false)); }); $app->get('/validate-rel-me/', function (Http\Request $request) { @@ -284,7 +287,9 @@ function datetimeProblem($datetimeStr) { $app->get('/validate-h-card/', function (Http\Request $request) use($app) { if (!$request->query->has('url')) { - return render('validate-h-card.html'); + return render('validate-h-card.html', [ + 'showResult' => false, + ]); } else { $url = IndieWeb\normaliseUrl($request->query->get('url')); @@ -305,9 +310,44 @@ function datetimeProblem($datetimeStr) { return $errorResponse(htmlspecialchars($err->getMessage())); } + $allHCards = Mf2\findMicroformatsByType($mfs, 'h-card'); + $representativeHCard = Mf2\getRepresentativeHCard($mfs, $url); + + /*header('Content-Type: text/plain; charset=utf8'); + var_dump($representativeHCard); + echo PHP_EOL . count($allHCards); + exit;*/ + + $firstHCard = null; + if (count($allHCards) > 0) { + $firstHCard = $allHCards[0]; + } + + return crossOriginResponse( + render( + 'validate-h-card.html', + [ + 'showResult' => true, + 'firstHCard' => $firstHCard, + 'allHCards' => $allHCards, + 'representativeHCards' => [], + 'representativeHCard' => $representativeHCard, + 'url' => htmlspecialchars($url) + ] + ) + ); + + + + + + + + print_r(Mf2\getRepresentativeHCard($mfs, $url)); exit; + $representativeHCards = array(); $allhCards = $hCards = Mf2\findMicroformatsByType($mfs, 'h-card'); - + $relMeUrls = empty($mfs['rels']['me']) ? array() : $mfs['rels']['me']; # check for `url` and `uid` properties matching the page URL @@ -322,9 +362,28 @@ function datetimeProblem($datetimeStr) { } } + // print_r($representativeHCards); + // exit; + # check for `url` property that matches a `rel=me` URL if ($relMeUrls) { foreach ($hCards as $index => $hCard) { + #print_r($hCard); exit; + + if (Mf2\hasProp($hCard, 'url')) { + print_r(MF2\getPlaintextArray($hCard, 'url')); exit; + } + + print_r($hCard['properties']['url']); exit; + + + $foo = array_filter($hCard['properties']['url'], function ($u) use ($relMeUrls) { + print_r($u); exit; + + }); + + + if (Mf2\hasProp($hCard, 'url') && count(array_filter($hCard['properties']['url'], function ($u) use ($relMeUrls) { return in_array(Indieweb\normaliseUrl($u), $relMeUrls); })) > 0) { @@ -334,6 +393,14 @@ function datetimeProblem($datetimeStr) { } } + print_r($representativeHCards); + exit; + + print_r($representativeHCards); + print_r($hCards); + #var_dump($err); + exit; + # check if the page has *one single h-card* and the `url` matches the page URL if (count($hCards) == 1) { $hCard = reset($hCards); From b8feff0ede3dbf5f6d961fe665313e2aa1a83148 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Wed, 29 Jun 2022 19:03:35 -0700 Subject: [PATCH 2/4] Remove inline rep h-card code Now using the mf-cleaner's getRepresentativeHCard method. --- web/index.php | 99 --------------------------------------------------- 1 file changed, 99 deletions(-) diff --git a/web/index.php b/web/index.php index a39c703..e668464 100644 --- a/web/index.php +++ b/web/index.php @@ -313,116 +313,17 @@ function datetimeProblem($datetimeStr) { $allHCards = Mf2\findMicroformatsByType($mfs, 'h-card'); $representativeHCard = Mf2\getRepresentativeHCard($mfs, $url); - /*header('Content-Type: text/plain; charset=utf8'); - var_dump($representativeHCard); - echo PHP_EOL . count($allHCards); - exit;*/ - - $firstHCard = null; - if (count($allHCards) > 0) { - $firstHCard = $allHCards[0]; - } - return crossOriginResponse( render( 'validate-h-card.html', [ 'showResult' => true, - 'firstHCard' => $firstHCard, 'allHCards' => $allHCards, - 'representativeHCards' => [], 'representativeHCard' => $representativeHCard, 'url' => htmlspecialchars($url) ] ) ); - - - - - - - - print_r(Mf2\getRepresentativeHCard($mfs, $url)); exit; - - $representativeHCards = array(); - $allhCards = $hCards = Mf2\findMicroformatsByType($mfs, 'h-card'); - - $relMeUrls = empty($mfs['rels']['me']) ? array() : $mfs['rels']['me']; - - # check for `url` and `uid` properties matching the page URL - foreach ($hCards as $index => $hCard) { - if (Mf2\hasProp($hCard, 'uid') && Mf2\hasProp($hCard, 'url') - && Mf2\urlsMatch(Mf2\getPlaintext($hCard, 'uid'), $url) - && count(array_filter($hCard['properties']['url'], function ($u) use ($url) { - return Mf2\urlsMatch($u, $url); - })) > 0) { - $representativeHCards[] = $hCard; - unset($hCards[$index]); - } - } - - // print_r($representativeHCards); - // exit; - - # check for `url` property that matches a `rel=me` URL - if ($relMeUrls) { - foreach ($hCards as $index => $hCard) { - #print_r($hCard); exit; - - if (Mf2\hasProp($hCard, 'url')) { - print_r(MF2\getPlaintextArray($hCard, 'url')); exit; - } - - print_r($hCard['properties']['url']); exit; - - - $foo = array_filter($hCard['properties']['url'], function ($u) use ($relMeUrls) { - print_r($u); exit; - - }); - - - - if (Mf2\hasProp($hCard, 'url') && count(array_filter($hCard['properties']['url'], function ($u) use ($relMeUrls) { - return in_array(Indieweb\normaliseUrl($u), $relMeUrls); - })) > 0) { - $representativeHCards[] = $hCard; - unset($hCards[$index]); - } - } - } - - print_r($representativeHCards); - exit; - - print_r($representativeHCards); - print_r($hCards); - #var_dump($err); - exit; - - # check if the page has *one single h-card* and the `url` matches the page URL - if (count($hCards) == 1) { - $hCard = reset($hCards); - if (Mf2\hasProp($hCard, 'url') && count(array_filter($hCard['properties']['url'], function ($u) use ($url) { - return Mf2\urlsMatch($u, $url); - })) > 0) { - $representativeHCards[] = $hCard; - } - } - - $firstHCard = null; - - if (count($allhCards) > 0) { - $firstHCard = $allhCards[0]; - } - - return crossOriginResponse(render('validate-h-card.html', array( - 'showResult' => true, - 'firstHCard' => $firstHCard, - 'representativeHCards' => $representativeHCards, - 'url' => htmlspecialchars($url) - ))); } }); From 7ba02201e373f5507a1b15fbef8cc1398334c887 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Wed, 29 Jun 2022 19:05:34 -0700 Subject: [PATCH 3/4] Remove debugging code --- web/index.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/web/index.php b/web/index.php index e668464..89ea775 100644 --- a/web/index.php +++ b/web/index.php @@ -2,9 +2,6 @@ namespace Indieweb\IndiewebifyMe; -error_reporting(E_ALL); -ini_set('display_errors', '1'); - ob_start(); require __DIR__ . '/../vendor/autoload.php'; ob_end_clean(); From f28233632acb683c1cecc1eb2b58b105c1740625 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Thu, 30 Jun 2022 13:57:38 -0700 Subject: [PATCH 4/4] Contextualize message for one/multiple h-cards found --- templates/validate-h-card.html.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/templates/validate-h-card.html.php b/templates/validate-h-card.html.php index 55f099c..7ce28e4 100644 --- a/templates/validate-h-card.html.php +++ b/templates/validate-h-card.html.php @@ -80,10 +80,16 @@

Success!

This representative h-card was found on your site:

- 0): $hCard = $allHCards[0]; ?> + 0): + $hCard = $allHCards[0]; + $intro_phrase = 'An h-card was found on your site! Consider '; + if (count($allHCards) > 1) { + $intro_phrase = 'Multiple h-cards were found on your site! Consider only having one and '; + } + ?>

Almost there!

-

Multiple h-cards were found on your site! Consider only having one and marking it up as the representative h-card.

+

marking it up as the representative h-card.

To identify the h-card that represents the page, you can:

  • Add class="u-url u-uid" on the h-card’s link to