Mentions
in package
This really is a pseudo class, I couldn't justify having instance of it while mentioning so I just made every method static
Table of Contents
Properties
- $char : string
- $excluded_bbc_regex : string
Methods
- getBody() : string
- Gets appropriate mentions replaced in the body
- getExistingMentions() : array<string|int, mixed>
- Like getPossibleMentions(), but for `[member=1]name[/member]` format.
- getMentionedMembers() : array<string|int, mixed>
- Takes a piece of text and finds all the mentioned members in it
- getMentionsByContent() : array<string|int, mixed>
- Returns mentions for a specific content
- getQuotedMembers() : array<string|int, mixed>
- Retrieves info about the authors of posts quoted in a block of text.
- insertMentions() : void
- Inserts mentioned members
- modifyMentions() : array<string|int, mixed>
- Updates list of mentioned members.
- verifyMentionedMembers() : array<string|int, mixed>
- Verifies that members really are mentioned in the text.
- getPossibleMentions() : array<string|int, mixed>
- Parses a body in order to see if there are any mentions, returns possible mention names
- setExcludedBbcRegex() : void
- Builds a regular expression matching BBC that can't contain mentions.
Properties
$char
protected
static string
$char
= '@'
The character used for mentioning users
$excluded_bbc_regex
protected
static string
$excluded_bbc_regex
= ''
Regular expression matching BBC that can't contain mentions
Methods
getBody()
Gets appropriate mentions replaced in the body
public
static getBody(string $body, array<string|int, mixed> $members) : string
Parameters
- $body : string
-
The text to look for mentions in
- $members : array<string|int, mixed>
-
An array of arrays containing info about members (each should have 'id' and 'member')
Tags
Return values
string —The body with mentions replaced
getExistingMentions()
Like getPossibleMentions(), but for `[member=1]name[/member]` format.
public
static getExistingMentions(string $body) : array<string|int, mixed>
Parameters
- $body : string
-
The text to look for mentions in.
Tags
Return values
array<string|int, mixed> —An array of arrays containing info about members that are in fact mentioned in the body.
getMentionedMembers()
Takes a piece of text and finds all the mentioned members in it
public
static getMentionedMembers(string $body) : array<string|int, mixed>
Parameters
- $body : string
-
The body to get mentions from
Tags
Return values
array<string|int, mixed> —An array of arrays containing members who were mentioned (each has 'id_member' and 'real_name')
getMentionsByContent()
Returns mentions for a specific content
public
static getMentionsByContent(string $content_type, int $content_id[, array<string|int, mixed> $members = [] ]) : array<string|int, mixed>
Parameters
- $content_type : string
-
The content type
- $content_id : int
-
The ID of the desired content
- $members : array<string|int, mixed> = []
-
Whether to limit to a specific set of members
Tags
Return values
array<string|int, mixed> —An array of arrays containing info about each member mentioned
getQuotedMembers()
Retrieves info about the authors of posts quoted in a block of text.
public
static getQuotedMembers(string $body, int $poster_id) : array<string|int, mixed>
Parameters
- $body : string
-
A block of text, such as the body of a post.
- $poster_id : int
-
The member ID of the author of the text.
Tags
Return values
array<string|int, mixed> —Info about any members who were quoted.
insertMentions()
Inserts mentioned members
public
static insertMentions(string $content_type, int $content_id, array<string|int, mixed> $members, int $id_member) : void
Parameters
- $content_type : string
-
The content type
- $content_id : int
-
The ID of the specified content
- $members : array<string|int, mixed>
-
An array of members who have been mentioned
- $id_member : int
-
The ID of the member who mentioned them
Tags
modifyMentions()
Updates list of mentioned members.
public
static modifyMentions(string $content_type, int $content_id, array<string|int, mixed> $members, int $id_member) : array<string|int, mixed>
Intended for use when a post is modified.
Parameters
- $content_type : string
-
The content type
- $content_id : int
-
The ID of the specified content
- $members : array<string|int, mixed>
-
An array of members who have been mentioned
- $id_member : int
-
The ID of the member who mentioned them
Tags
Return values
array<string|int, mixed> —An array of unchanged, removed, and added member IDs.
verifyMentionedMembers()
Verifies that members really are mentioned in the text.
public
static verifyMentionedMembers(string $body, array<string|int, mixed> $members) : array<string|int, mixed>
This function assumes the incoming text has already been processed by the Mentions::getBody() function.
Parameters
- $body : string
-
The text to look for mentions in.
- $members : array<string|int, mixed>
-
An array of arrays containing info about members (each should have 'id' and 'member').
Tags
Return values
array<string|int, mixed> —An array of arrays containing info about members that are in fact mentioned in the body.
getPossibleMentions()
Parses a body in order to see if there are any mentions, returns possible mention names
protected
static getPossibleMentions(string $body) : array<string|int, mixed>
Names are tagged by "@
One potential problem with this is something like "@Admin Space" can match "Admin Space" as well as "Admin", so we sort by length in descending order. One disadvantage of this is that we can only match by one column, hence I've chosen real_name since it's the most obvious.
If there's an @ symbol within the name, it is counted in the ongoing string and a new combination string is started from it as well in order to account for all the possibilities. This makes the @ symbol to not be required to be escaped
Parameters
- $body : string
-
The text to look for mentions in
Tags
Return values
array<string|int, mixed> —An array of names of members who have been mentioned
setExcludedBbcRegex()
Builds a regular expression matching BBC that can't contain mentions.
protected
static setExcludedBbcRegex() : void