Add hashtag support
rodzic
7269503af6
commit
00a78af84c
40
index.php
40
index.php
|
@ -367,6 +367,9 @@ HTML;
|
|||
// Get the posted content
|
||||
$content = $_POST["content"];
|
||||
|
||||
// Process the content into HTML to get hashtags etc
|
||||
list( "HTML" => $content, "TagArray" => $tags ) = process_content( $content );
|
||||
|
||||
// Current time - ISO8601
|
||||
$timestamp = date( "c" );
|
||||
|
||||
|
@ -386,7 +389,8 @@ HTML;
|
|||
"attributedTo" => "https://{$server}/{$username}",
|
||||
"content" => $content,
|
||||
"contentMap" => ["en" => $content],
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"tag" => $tags
|
||||
];
|
||||
|
||||
// Construct the Message
|
||||
|
@ -462,6 +466,40 @@ HTML;
|
|||
die();
|
||||
}
|
||||
|
||||
// Content can be plain text. But to add clickable links and hashtags, it needs to be turned into HTML.
|
||||
// Tags are also included separately in the message
|
||||
function process_content( $content ) {
|
||||
global $server;
|
||||
|
||||
// Get any hashtags
|
||||
$hashtags = [];
|
||||
preg_match_all( '/#(\w+)/', $content, $matches );
|
||||
foreach ($matches[1] as $match) {
|
||||
$hashtags[] = $match;
|
||||
}
|
||||
|
||||
// Construct the tag value for the note object
|
||||
$tags = [];
|
||||
foreach ( $hashtags as $hashtag ) {
|
||||
$tags[] = array(
|
||||
"type" => "Hashtag",
|
||||
"name" => "#{$hashtag}",
|
||||
);
|
||||
}
|
||||
|
||||
// Add HTML links for hashtags into the text
|
||||
$content = preg_replace(
|
||||
'/(?<!\S)#([0-9\p{L}]+)/u',
|
||||
"<a href='https://{$server}/tag/$1'>#$1</a>",
|
||||
$content
|
||||
);
|
||||
|
||||
// Construct the content
|
||||
$content = "<p>{$content}</p>";
|
||||
|
||||
return ["HTML" => $content, "TagArray" => $tags];
|
||||
}
|
||||
|
||||
// "One to stun, two to kill, three to make sure"
|
||||
die();
|
||||
die();
|
||||
|
|
Ładowanie…
Reference in New Issue