Improved formatting
This commit is contained in:
parent
0a4119adaf
commit
4e5db36177
3 changed files with 71 additions and 65 deletions
|
@ -487,7 +487,7 @@ class BBCode
|
|||
|
||||
/**
|
||||
* Truncates imported message body string length to max_import_size
|
||||
*
|
||||
*
|
||||
* The purpose of this function is to apply system message length limits to
|
||||
* imported messages without including any embedded photos in the length
|
||||
*
|
||||
|
@ -712,6 +712,7 @@ class BBCode
|
|||
|
||||
/**
|
||||
* Converts [url] BBCodes in a format that looks fine on ActivityPub systems.
|
||||
*
|
||||
* @param string $url URL that is about to be reformatted
|
||||
* @return string reformatted link including HTML codes
|
||||
*/
|
||||
|
@ -723,6 +724,7 @@ class BBCode
|
|||
|
||||
/**
|
||||
* Converts an URL in a nicer format (without the scheme and possibly shortened)
|
||||
*
|
||||
* @param string $url URL that is about to be reformatted
|
||||
* @return string reformatted link
|
||||
*/
|
||||
|
@ -2063,76 +2065,79 @@ class BBCode
|
|||
}
|
||||
|
||||
/**
|
||||
* Pull out all #hashtags and @person tags from $string.
|
||||
*
|
||||
* We also get @person@domain.com - which would make
|
||||
* the regex quite complicated as tags can also
|
||||
* end a sentence. So we'll run through our results
|
||||
* and strip the period from any tags which end with one.
|
||||
* Returns array of tags found, or empty array.
|
||||
*
|
||||
* @param string $string Post content
|
||||
*
|
||||
* @return array List of tag and person names
|
||||
*/
|
||||
public static function getTags($string)
|
||||
{
|
||||
$ret = [];
|
||||
* Pull out all #hashtags and @person tags from $string.
|
||||
*
|
||||
* We also get @person@domain.com - which would make
|
||||
* the regex quite complicated as tags can also
|
||||
* end a sentence. So we'll run through our results
|
||||
* and strip the period from any tags which end with one.
|
||||
* Returns array of tags found, or empty array.
|
||||
*
|
||||
* @param string $string Post content
|
||||
*
|
||||
* @return array List of tag and person names
|
||||
*/
|
||||
public static function getTags($string)
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
// Convert hashtag links to hashtags
|
||||
$string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2', $string);
|
||||
// Convert hashtag links to hashtags
|
||||
$string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2', $string);
|
||||
|
||||
// ignore anything in a code block
|
||||
$string = preg_replace('/\[code.*?\].*?\[\/code\]/sm', '', $string);
|
||||
// ignore anything in a code block
|
||||
$string = preg_replace('/\[code.*?\].*?\[\/code\]/sm', '', $string);
|
||||
|
||||
// Force line feeds at bbtags
|
||||
$string = str_replace(['[', ']'], ["\n[", "]\n"], $string);
|
||||
// Force line feeds at bbtags
|
||||
$string = str_replace(['[', ']'], ["\n[", "]\n"], $string);
|
||||
|
||||
// ignore anything in a bbtag
|
||||
$string = preg_replace('/\[(.*?)\]/sm', '', $string);
|
||||
// ignore anything in a bbtag
|
||||
$string = preg_replace('/\[(.*?)\]/sm', '', $string);
|
||||
|
||||
// Match full names against @tags including the space between first and last
|
||||
// We will look these up afterward to see if they are full names or not recognisable.
|
||||
// Match full names against @tags including the space between first and last
|
||||
// We will look these up afterward to see if they are full names or not recognisable.
|
||||
|
||||
if (preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A@,:?]+)([ \x0D\x0A@,:?]|$)/', $string, $matches)) {
|
||||
foreach ($matches[1] as $match) {
|
||||
if (strstr($match, ']')) {
|
||||
// we might be inside a bbcode color tag - leave it alone
|
||||
continue;
|
||||
}
|
||||
if (preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A@,:?]+)([ \x0D\x0A@,:?]|$)/', $string, $matches)) {
|
||||
foreach ($matches[1] as $match) {
|
||||
if (strstr($match, ']')) {
|
||||
// we might be inside a bbcode color tag - leave it alone
|
||||
continue;
|
||||
}
|
||||
|
||||
if (substr($match, -1, 1) === '.') {
|
||||
$ret[] = substr($match, 0, -1);
|
||||
} else {
|
||||
$ret[] = $match;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (substr($match, -1, 1) === '.') {
|
||||
$ret[] = substr($match, 0, -1);
|
||||
} else {
|
||||
$ret[] = $match;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise pull out single word tags. These can be @nickname, @first_last
|
||||
// and #hash tags.
|
||||
// Otherwise pull out single word tags. These can be @nickname, @first_last
|
||||
// and #hash tags.
|
||||
|
||||
if (preg_match_all('/([!#@][^\^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/', $string, $matches)) {
|
||||
foreach ($matches[1] as $match) {
|
||||
if (strstr($match, ']')) {
|
||||
// we might be inside a bbcode color tag - leave it alone
|
||||
continue;
|
||||
}
|
||||
if (substr($match, -1, 1) === '.') {
|
||||
$match = substr($match,0,-1);
|
||||
}
|
||||
// ignore strictly numeric tags like #1
|
||||
if ((strpos($match, '#') === 0) && ctype_digit(substr($match, 1))) {
|
||||
continue;
|
||||
}
|
||||
// try not to catch url fragments
|
||||
if (strpos($string, $match) && preg_match('/[a-zA-z0-9\/]/', substr($string, strpos($string, $match) - 1, 1))) {
|
||||
continue;
|
||||
}
|
||||
$ret[] = $match;
|
||||
}
|
||||
}
|
||||
if (preg_match_all('/([!#@][^\^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/', $string, $matches)) {
|
||||
foreach ($matches[1] as $match) {
|
||||
if (strstr($match, ']')) {
|
||||
// we might be inside a bbcode color tag - leave it alone
|
||||
continue;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
if (substr($match, -1, 1) === '.') {
|
||||
$match = substr($match,0,-1);
|
||||
}
|
||||
|
||||
// ignore strictly numeric tags like #1
|
||||
if ((strpos($match, '#') === 0) && ctype_digit(substr($match, 1))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// try not to catch url fragments
|
||||
if (strpos($string, $match) && preg_match('/[a-zA-z0-9\/]/', substr($string, strpos($string, $match) - 1, 1))) {
|
||||
continue;
|
||||
}
|
||||
$ret[] = $match;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1949,7 +1949,7 @@ class Contact
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Helper function for "updateFromProbe". Updates personal and public contact
|
||||
*
|
||||
* @param integer $id contact id
|
||||
|
@ -2008,7 +2008,7 @@ class Contact
|
|||
DBA::update('contact', $fields, $condition);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Remove duplicated contacts
|
||||
*
|
||||
* @param string $nurl Normalised contact url
|
||||
|
|
|
@ -1228,6 +1228,7 @@ class GContact
|
|||
|
||||
/**
|
||||
* Asking GNU Social server on a regular base for their user data
|
||||
*
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
|
|
Loading…
Reference in a new issue