Skip to content

Fix implied photo parsing#191

Merged
aaronpk merged 4 commits into
microformats:masterfrom
gRegorLove:issue190
Aug 23, 2018
Merged

Fix implied photo parsing#191
aaronpk merged 4 commits into
microformats:masterfrom
gRegorLove:issue190

Conversation

@gRegorLove
Copy link
Copy Markdown
Member

Fixes #190

@gRegorLove gRegorLove requested review from Zegnat and aaronpk August 7, 2018 01:48
Comment thread Mf2/Parser.php Outdated
'./object',
'./*[not(contains(concat(" ", @class), " h-"))]/img[count(preceding-sibling::img)+count(following-sibling::img)=0]',
'./*[not(contains(concat(" ", @class), " h-"))]/object[count(preceding-sibling::object)+count(following-sibling::object)=0]',
'./*[count(preceding-sibling::*)+count(following-sibling::*)=0][not(contains(concat(" ", @class), " h-"))]/img[count(preceding-sibling::img)+count(following-sibling::img)=0]',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this XPath a little easier to read perhaps? I still need to test it, but seems like something as follows should do the same without requiring arithmetic:

./*[not(contains(concat(" ", @class), " h-")) and count(../*) = 1 and count(img) = 1]/img
  • count(../*) counts the number of child elements of the parent. In other words our * is only matched if it is the only child (= 1).
  • count(img) counts the number of child img elements within. So * is only matched if it contains only a single img (= 1).

This gets rid of all the sibling counting, summations, etc. Could also be adapted for object elements.

Simplified xpath count() using traversal.
Added selectors from spec as comments.
Moved child h-* check into xpaths.
Added check for xpath query() returning false.
Comment thread Mf2/Parser.php

if ($photo !== false) {
$return['photo'][] = $this->resolveUrl($photo);
$return['photo'][] = $photo;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without resolving here, the implied values from img.h-x[src] and object.h-x[data] will never get resolved. Why not keep resolveUrl() here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add resolveUrl to those two. My thinking is parseImpliedPhoto() should return an absolute URL or false.

@Zegnat
Copy link
Copy Markdown
Member

Zegnat commented Aug 7, 2018

LGTM 👍

@aaronpk aaronpk merged commit ab56749 into microformats:master Aug 23, 2018
@gRegorLove gRegorLove deleted the issue190 branch July 8, 2022 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants