API / Minn\Content / TextFilters

TextFilters final class

Minn\Content\TextFilters · public/minn/src/Minn/Content/TextFilters.php · 161 lines

The small text filters the reference runs over content, titles and comments, each from its observed rules (contracts/runtime.md "The content filters", "The comment form"): smilies, the capital P, insecure home addresses, the feed's embed clean-up, and a comment's links and spans.

Constants and properties

privateIMAGE = '/\\.(png|gif|jpe?g|svg|webp)$/i'
privateIGNORED = array ( 0 => 'code', 1 => 'pre', 2 => 'script', 3 => 'style', 4 => 'textarea', )

Public

staticsmiliesSearch(array $codes): string#

The search pattern smilies_init leaves in $wp_smiliessearch, from the codes in their stored order (reverse-sorted): one alternative per first character, its code's rest quoted and joined, each bounded by whitespace, a no-break space or the line's ends (probe functions-utils).

$codeslist<string>
staticsmilies(string $text, array $table, Closure $image): string#

Smilies become their emoji, or an image for the few that have one: a code only counts as a whole word between spaces, and nothing inside a code, pre, script, style or textarea element, or inside a tag, changes.

$tablearray<string, string>code => emoji, or an image file name
staticcapitalP(string $text): string#

"Wordpress" spelled right after a space, a parenthesis, a tag, or an opening curly quote; elsewhere it stays.

staticcapitalPEverywhere(string $text): string#

"Wordpress" spelled right everywhere, as a title is.

staticsecureHome(string $content, string $insecure, string $secure): string#

The site's own http address made https, escaped forms included.

staticfeedEmbeds(string $content): string#

A feed carries an embedded post's iframe without the style that hides it until its script runs.

staticrel(string $slashed, string $rel, Closure $internal): string#

Every link given a rel (wp_rel_nofollow, wp_rel_ugc), on slashed text as the content filters carry it, slashed again after (probes comment-fields, plugin-queue5). A link to the site itself does not take "nofollow".

staticlinkRel(string $inner, string $rel, Closure $internal): string#

One link's opening tag with the rel added (wp_rel_callback): a tag that has a rel keeps its words first, gains the new ones, and is written again with every attribute double-quoted and rel last; one without keeps its attributes as written and takes rel at the end.

staticnoteMentionClasses(string $slashed): string#

A span keeps no class in a comment (where a note's mention would be faked); slashed text in, slashed out.

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateignoring(string $tag, ?string $current): ?string#

The element whose text is left alone after a tag: one of the ignored elements opening, or the one still open.

privatewords(string $text, array $table, Closure $image): string#

One text run, word by word. @param array<string, string> $table

$tablearray<string, string>
privateattributes(string $raw): array#

A tag's attributes in order, name => value (quotes removed; a bare name has null). @return array<string, ?string>

@return array<string, ?string>