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