Documentation

Application

Table of Contents

FALSE_POSITIVE_ROOT_CLASSNAME_REGEXES  = [ // https://tailwindcss.com/docs/height '/h-px/', '/h-auto/', '/h-full/', '/h-screen/', '/h-min/', '/h-max/', '/h-fit/', // https://chat.indieweb.org/dev/2022-11-14/1668463558928800 '/h-screen-[a-zA-Z0-9\\-\\_]+/', '/h-full-[a-zA-Z0-9\\-\\_]+/', ]
hasNumericKeys()  : bool
Iterates over array keys, returns true if has numeric keys.
isMicroformat()  : bool
Verifies if $mf is an array without numeric keys, and has a 'properties' key.
isMicroformatCollection()  : bool
Verifies if $mf has an 'items' key which is also an array, returns true.
isEmbeddedHtml()  : bool
Verifies if $p is an array without numeric keys and has key 'value' and 'html' set.
isImgAlt()  : bool
Checks to see if the passed value is an img-alt structure.
hasProp()  : bool
Verifies if property named $propName is in array $mf.
getProp()  : mixed|null
shortcut for getPlaintext.
toPlaintext()  : mixed
If $v is a microformat, embedded html, or img-alt structure, return $v['value']. Else return v.
getPlaintext()  : mixed|null
Returns plaintext of $propName with optional $fallback
getPlaintextArray()  : mixed
Converts $propName in $mf into array_map plaintext, or $fallback if not valid.
toHtml()  : mixed
Returns ['html'] element of $v, or ['value'] or just $v, in order of availablility.
getHtml()  : mixed|null
Gets HTML of $propName or if not, $fallback
toImgAlt()  : array<string|int, mixed>
To img-alt
getImgAlt()  : array<string|int, mixed>|mixed
Get img-alt
getSummary()  : mixed|null|string
Returns 'summary' element of $mf or a truncated Plaintext of $mf['properties']['content'] with 19 chars and ellipsis.
getPublished()  : mixed|null
Gets the date published of $mf array.
getUpdated()  : mixed|null
Gets the date updated of $mf array.
getDateTimeProperty()  : mixed|null
Gets the DateTime properties including published or updated, depending on params.
sameHostname()  : bool
True if same hostname is parsed on both
getAuthor()  : mixed|null
Large function for fishing out author of $mf from various possible array elements.
parseUrl()  : mixed
Returns array per parse_url standard with pathname key added.
urlsMatch()  : bool
See if urls match for each component of parsed urls. Return true if so.
anyUrlsMatch()  : bool
Given two arrays of URLs, determine if any of them match
getRepresentativeHCard()  : array<string|int, mixed>|null
Representative h-card
flattenMicroformatProperties()  : array<string|int, mixed>
Makes microformat properties into a flattened array, returned.
flattenMicroformats()  : array<string|int, mixed>
Flattens microformats. Can intake multiple Microformats including possible MicroformatCollection.
findMicroformatsByType()  : mixed
Find Microformats By Type
findMicroformatsByProperty()  : mixed
findMicroformatsByCallable()  : mixed
$callable should be a function or an exception will be thrown. $mfs can accept microformat collections.
removeFalsePositiveRootMicroformats()  : mixed
Remove False Positive Root Microformats

Constants

FALSE_POSITIVE_ROOT_CLASSNAME_REGEXES

public mixed FALSE_POSITIVE_ROOT_CLASSNAME_REGEXES = [ // https://tailwindcss.com/docs/height '/h-px/', '/h-auto/', '/h-full/', '/h-screen/', '/h-min/', '/h-max/', '/h-fit/', // https://chat.indieweb.org/dev/2022-11-14/1668463558928800 '/h-screen-[a-zA-Z0-9\\-\\_]+/', '/h-full-[a-zA-Z0-9\\-\\_]+/', ]

Functions

hasNumericKeys()

Iterates over array keys, returns true if has numeric keys.

hasNumericKeys(array<string|int, mixed> $arr) : bool
Parameters
$arr : array<string|int, mixed>
Return values
bool

isMicroformat()

Verifies if $mf is an array without numeric keys, and has a 'properties' key.

isMicroformat( $mf) : bool
Parameters
$mf :
Return values
bool

isMicroformatCollection()

Verifies if $mf has an 'items' key which is also an array, returns true.

isMicroformatCollection( $mf) : bool
Parameters
$mf :
Return values
bool

isEmbeddedHtml()

Verifies if $p is an array without numeric keys and has key 'value' and 'html' set.

isEmbeddedHtml( $p) : bool
Parameters
$p :
Return values
bool

isImgAlt()

Checks to see if the passed value is an img-alt structure.

isImgAlt( $p) : bool
Parameters
$p :
Return values
bool

hasProp()

Verifies if property named $propName is in array $mf.

hasProp(array<string|int, mixed> $mf,  $propName) : bool
Parameters
$mf : array<string|int, mixed>
$propName :
Return values
bool

getProp()

shortcut for getPlaintext.

getProp(array<string|int, mixed> $mf,  $propName[, null|string $fallback = null ]) : mixed|null
Parameters
$mf : array<string|int, mixed>
$propName :
$fallback : null|string = null
Tags
deprecated

use getPlaintext from now on

Return values
mixed|null

toPlaintext()

If $v is a microformat, embedded html, or img-alt structure, return $v['value']. Else return v.

toPlaintext( $v) : mixed
Parameters
$v :
Return values
mixed

getPlaintext()

Returns plaintext of $propName with optional $fallback

getPlaintext(array<string|int, mixed> $mf,  $propName[, null|string $fallback = null ]) : mixed|null
Parameters
$mf : array<string|int, mixed>
$propName :
$fallback : null|string = null
Tags
link
http://php.net/manual/en/function.current.php
Return values
mixed|null

getPlaintextArray()

Converts $propName in $mf into array_map plaintext, or $fallback if not valid.

getPlaintextArray(array<string|int, mixed> $mf,  $propName[, mixed $fallback = null ]) : mixed
Parameters
$mf : array<string|int, mixed>
$propName :
$fallback : mixed = null

default null

Return values
mixed

toHtml()

Returns ['html'] element of $v, or ['value'] or just $v, in order of availablility.

toHtml( $v) : mixed
Parameters
$v :
Return values
mixed

getHtml()

Gets HTML of $propName or if not, $fallback

getHtml(array<string|int, mixed> $mf,  $propName[, null|string $fallback = null ]) : mixed|null
Parameters
$mf : array<string|int, mixed>
$propName :
$fallback : null|string = null
Return values
mixed|null

toImgAlt()

To img-alt

toImgAlt( $v) : array<string|int, mixed>

Converts a value to an img-alt {'value': '', 'alt': ''} structure. Passes through existing img-alt structures unchanged. For anything else, converts it to its plaintext representation, put that in the value key, and adds an empty alt key.

Parameters
$v :
Return values
array<string|int, mixed>

getImgAlt()

Get img-alt

getImgAlt(array<string|int, mixed> $mf, string $propName[, mixed $fallback = null ]) : array<string|int, mixed>|mixed

If $propName exists on $mf, return an img-alt representation of it (via toImgAlt). If the property does not exist, return $fallback (default null)

Parameters
$mf : array<string|int, mixed>
$propName : string
$fallback : mixed = null
Return values
array<string|int, mixed>|mixed

getSummary()

Returns 'summary' element of $mf or a truncated Plaintext of $mf['properties']['content'] with 19 chars and ellipsis.

getSummary(array<string|int, mixed> $mf) : mixed|null|string
Parameters
$mf : array<string|int, mixed>
Tags
deprecated

as not often used

Return values
mixed|null|string

getPublished()

Gets the date published of $mf array.

getPublished(array<string|int, mixed> $mf[, bool $ensureValid = false ][, null|string $fallback = null ]) : mixed|null
Parameters
$mf : array<string|int, mixed>
$ensureValid : bool = false
$fallback : null|string = null

optional result if date not available

Return values
mixed|null

getUpdated()

Gets the date updated of $mf array.

getUpdated(array<string|int, mixed> $mf[, bool $ensureValid = false ][, null $fallback = null ]) : mixed|null
Parameters
$mf : array<string|int, mixed>
$ensureValid : bool = false
$fallback : null = null
Return values
mixed|null

getDateTimeProperty()

Gets the DateTime properties including published or updated, depending on params.

getDateTimeProperty( $name, array<string|int, mixed> $mf[, bool $ensureValid = false ][, null|string $fallback = null ]) : mixed|null
Parameters
$name :

string updated or published

$mf : array<string|int, mixed>
$ensureValid : bool = false
$fallback : null|string = null
Return values
mixed|null

getAuthor()

Large function for fishing out author of $mf from various possible array elements.

getAuthor(array<string|int, mixed> $mf[, array<string|int, mixed>|null $context = null ][, null $url = null ][, bool $matchName = true ][, bool $matchHostname = true ]) : mixed|null
Parameters
$mf : array<string|int, mixed>
$context : array<string|int, mixed>|null = null
$url : null = null
$matchName : bool = true
$matchHostname : bool = true
Tags
todo:

this needs to be just part of an indiewebcamp.com/authorship algorithm, at the moment it tries to do too much

todo:

maybe split some bits of this out into separate functions

Return values
mixed|null

urlsMatch()

See if urls match for each component of parsed urls. Return true if so.

urlsMatch( $url1,  $url2) : bool
Parameters
$url1 :
$url2 :
Tags
see
parseUrl()
Return values
bool

anyUrlsMatch()

Given two arrays of URLs, determine if any of them match

anyUrlsMatch(mixed $array1, mixed $array2) : bool
Parameters
$array1 : mixed
$array2 : mixed
Return values
bool

getRepresentativeHCard()

Representative h-card

getRepresentativeHCard(array<string|int, mixed> $mfs, string $url) : array<string|int, mixed>|null

Given the microformats on a page representing a person or organisation (h-card), find the single h-card which is representative of the page, or null if none is found.

Parameters
$mfs : array<string|int, mixed>

The parsed microformats of a page to search for a representative h-card

$url : string

The URL the microformats were fetched from

Tags
see
http://microformats.org/wiki/representative-h-card-parsing
Return values
array<string|int, mixed>|null

Either a single h-card array structure, or null if none was found

flattenMicroformatProperties()

Makes microformat properties into a flattened array, returned.

flattenMicroformatProperties(array<string|int, mixed> $mf) : array<string|int, mixed>
Parameters
$mf : array<string|int, mixed>
Return values
array<string|int, mixed>

flattenMicroformats()

Flattens microformats. Can intake multiple Microformats including possible MicroformatCollection.

flattenMicroformats(array<string|int, mixed> $mfs) : array<string|int, mixed>
Parameters
$mfs : array<string|int, mixed>
Return values
array<string|int, mixed>

findMicroformatsByType()

Find Microformats By Type

findMicroformatsByType(array<string|int, mixed> $mfs,  $name[, bool $flatten = true ]) : mixed

Traverses a mf2 tree and returns all microformats objects whose type matches the one given.

Parameters
$mfs : array<string|int, mixed>
$name :
$flatten : bool = true
Return values
mixed

findMicroformatsByProperty()

findMicroformatsByProperty(array<string|int, mixed> $mfs,  $propName,  $propValue[, bool $flatten = true ]) : mixed
Parameters
$mfs : array<string|int, mixed>
$propName :
$propValue :
$flatten : bool = true
Tags
see
findMicroformatsByCallable()
Return values
mixed

findMicroformatsByCallable()

$callable should be a function or an exception will be thrown. $mfs can accept microformat collections.

findMicroformatsByCallable(array<string|int, mixed> $mfs,  $callable[, bool $flatten = true ]) : mixed

If $flatten is true then the result will be flattened.

Parameters
$mfs : array<string|int, mixed>
$callable :
$flatten : bool = true
Tags
link
http://php.net/manual/en/function.is-callable.php
see
flattenMicroformats()
Return values
mixed

removeFalsePositiveRootMicroformats()

Remove False Positive Root Microformats

removeFalsePositiveRootMicroformats(array<string|int, mixed> $mfs[, array<string|int, mixed>|null $classnamesToRemove = null ]) : mixed

Unfortunately, a well-known CSS framework uses some non-semantic classnames which look like root classnames to the microformats2 parsing algorithm. This function takes either a single microformat or a mf2 tree and restructures it as if the false positive classnames had never been there.

Always returns a microformat collection ({"items": []}) even when passed a single microformat, as if the single microformat was a false positive, it may be replaced with more than one child.

The default list of known false positives is stored in FALSE_POSITIVE_ROOT_CLASSNAME_REGEXES and is used by default. You can provide your own list if you want. Some of the known false positives are prefixes, so the values of $classnamesToRemove must all be regexes (e.g. '/h-wrong/').

Parameters
$mfs : array<string|int, mixed>
$classnamesToRemove : array<string|int, mixed>|null = null
Return values
mixed

Search results