Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TextFormatter attribute order for Flarum post mentions #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Parser/Flarum/QuoteEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function render(Lexer $lexer)
// Omits 'p' tags that wrap <POSTMENTION> thru {body} normally because we don't know if the body has 'p' tags.
$this->wrapElement('<QUOTE><i>&gt; </i>' .
// Postscript will fill in blank attributes BUT THEY MUST BE IN THIS ORDER.
'<POSTMENTION id="{postid}" discussionid="{discussionid}" number="" displayname="{author}">' .
'<POSTMENTION discussionid="{discussionid}" displayname="{author}" id="{postid}" number="">' .
'@"{author}"#p{postid}</POSTMENTION> {body}</QUOTE>', ['author', 'postid', 'body', 'discussionid']);
}
}
18 changes: 9 additions & 9 deletions src/Postscript/Flarum.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function numberPosts(ExportModel $ex)
/**
* Find mentions in posts and record to database table.
*
* @see QuoteEmbed — '<POSTMENTION id="{postid}" discussionid="" number="" displayname="{author}">'
* @see QuoteEmbed — '<POSTMENTION discussionid="" displayname="{author}" id="{postid}" number="">'
*/
protected function buildPostMentions(ExportModel $ex)
{
Expand Down Expand Up @@ -163,7 +163,7 @@ protected function buildPostMentions(ExportModel $ex)
// Find converted mentions and connect to userID.
$mentions = [];
preg_match_all(
'/<POSTMENTION id="(?<postids>[0-9]*)" discussionid="(?<discussionids>[0-9]*)".*\/POSTMENTION>/U',
'/<POSTMENTION discussionid="(?<discussionids>[0-9]*)".* id="(?<postids>[0-9]*)".*\/POSTMENTION>/U',
$post->content,
$mentions
);
Expand Down Expand Up @@ -222,7 +222,7 @@ protected function buildPostMentions(ExportModel $ex)
* @param int $quoteID The post referenced in the content.
* @param string $quoteType One of 'post' or 'discussion'.
* @return bool Whether the post mention was repaired.
*@see QuoteEmbed — '<POSTMENTION id="{postid}" discussionid="" number="" displayname="{author}">'
*@see QuoteEmbed — '<POSTMENTION discussionid="" displayname="{author}" id="{postid}" number="">'
*/
protected function repairPostMention(ExportModel $ex, int $postid, string $content, int $quoteID, string $quoteType)
{
Expand Down Expand Up @@ -253,16 +253,16 @@ protected function repairPostMention(ExportModel $ex, int $postid, string $conte
// Swap it into the mention markup.
// Only one of these will match and it's easier than a logic gate.
$body = str_replace(
'<POSTMENTION id="' . $quoteID . '" discussionid="" number=""',
'<POSTMENTION id="' . $quoteID .
'" discussionid="' . $quotedPost->discussion_id .
'<POSTMENTION discussionid="" displayname="" id="' . $quoteID . '" number=""',
'<POSTMENTION discussionid="' . $quotedPost->discussion_id .
'" displayname="" id="' . $quoteID .
'" number="' . $quotedPost->number . '"',
$content
);
$body = str_replace(
'<POSTMENTION id="" discussionid="' . $quoteID . '" number=""',
'<POSTMENTION id="' . $quotedPost->id .
'" discussionid="' . $quoteID .
'<POSTMENTION discussionid="' . $quoteID . '" displayname="" id="" number=""',
'<POSTMENTION discussionid="' . $quoteID .
'" displayname="" id="' . $quotedPost->id .
'" number="' . $quotedPost->number . '"',
$content
);
Expand Down
Loading