Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -58,11 +58,6 @@ class _LegacyParser
|
||||
*/
|
||||
public $emoticons = NULL;
|
||||
|
||||
/**
|
||||
* @brief Media tags
|
||||
*/
|
||||
public $media = NULL;
|
||||
|
||||
/**
|
||||
* Can use plugin?
|
||||
*
|
||||
@@ -193,23 +188,6 @@ class _LegacyParser
|
||||
unset( $this->bbcodes[ $tag ] );
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( $this->bbcodes['media'] ) )
|
||||
{
|
||||
$this->bbcodes['media']['bbcode_replace'] = '<p>{content}</p>';
|
||||
}
|
||||
|
||||
if( $this->media === null )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->media = iterator_to_array( \IPS\Db::i()->select( '*', 'bbcode_mediatag' ) );
|
||||
}
|
||||
catch( \IPS\Db\Exception $e )
|
||||
{
|
||||
$this->media = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,14 +211,14 @@ class _LegacyParser
|
||||
if ( \stristr( $value, '<br>' ) || \stristr( $value, '<br />' ) || \stristr( $value, '<p>' ) )
|
||||
{
|
||||
/* Protect code tags first... */
|
||||
$value = preg_replace_callback( "/\[code.*?\](.+?)\[\/code\]/ims", function( $match ) use ( &$codeBlocks ) {
|
||||
$hash = md5( uniqid() );
|
||||
$value = preg_replace_callback( "/\[(?:code|codebox|sql|php|xml|html).*?\](.+?)\[\/(?:code|codebox|sql|php|xml|html)\]/ims", function( $match ) use ( &$codeBlocks ) {
|
||||
$hash = md5( $match[0] . mt_rand() );
|
||||
$codeBlocks[ $hash ] = ( \stristr( $match[0], '<br>' ) || \stristr( $match[0], '<br />' ) || \stristr( $match[0], '<p>' ) ) ? \str_replace( "\n", "", $match[0] ) : $match[0];
|
||||
return $hash;
|
||||
}, $value );
|
||||
|
||||
$value = preg_replace_callback( "/\<pre\s+?class=[\"']_prettyXprint(?:.*?)[\"']\>(.+?)\<\/pre\>/ims", function( $match ) use ( &$codeBlocks ) {
|
||||
$hash = md5( uniqid() );
|
||||
$hash = md5( $match[0] . mt_rand() );
|
||||
$codeBlocks[ $hash ] = ( \stristr( $match[0], '<br>' ) || \stristr( $match[0], '<br />' ) || \stristr( $match[0], '<p>' ) ) ? \str_replace( "\n", "", $match[0] ) : $match[0];
|
||||
return $hash;
|
||||
}, $value );
|
||||
@@ -249,6 +227,15 @@ class _LegacyParser
|
||||
}
|
||||
}
|
||||
|
||||
/* If we allow HTML we have to swap out entities - codeblocks are already protected at this point */
|
||||
if( $this->allowHtml )
|
||||
{
|
||||
/* Fixes an issue with legacy posts */
|
||||
$value = str_replace( '"', '"', $value );
|
||||
$value = str_replace( '<', '<', $value );
|
||||
$value = str_replace( '>', '>', $value );
|
||||
}
|
||||
|
||||
$value = nl2br( $value );
|
||||
|
||||
/* If we had any code blocks, put them back now */
|
||||
@@ -344,6 +331,18 @@ class _LegacyParser
|
||||
$value = str_replace( $m, $replacement, $value );
|
||||
}
|
||||
|
||||
preg_match_all( "/\<pre\s+?class=[\"']_prettyXprint(?:.*?)[\"']\>(.+?)\<\/pre\>/ims", $value, $matches );
|
||||
|
||||
foreach( $matches[0] as $k => $m )
|
||||
{
|
||||
$c = count( $codeboxes );
|
||||
$codeboxes[ $c ] = $m;
|
||||
|
||||
$replacement = '<!--codeboxes{' . $c . '}-->';
|
||||
|
||||
$value = str_replace( $m, $replacement, $value );
|
||||
}
|
||||
|
||||
/* Nested spoilers do not parse correctly, so just do that manually here for now */
|
||||
$value = str_replace( "[spoiler]", '</p><div class="ipsSpoiler" data-ipsSpoiler><div class="ipsSpoiler_header"><span></span></div><div class="ipsSpoiler_contents"><p>', $value );
|
||||
$value = str_replace( "[/spoiler]", "</p></div></div><p>", $value );
|
||||
@@ -715,7 +714,7 @@ class _LegacyParser
|
||||
}
|
||||
}
|
||||
catch( \UnexpectedValueException $e ){}
|
||||
|
||||
|
||||
$value = str_replace( $m, $replacement, $value );
|
||||
}
|
||||
|
||||
@@ -730,20 +729,22 @@ class _LegacyParser
|
||||
$value = str_replace( $m, '<!--url{' . $c . '}-->', $value );
|
||||
}
|
||||
|
||||
/* Media URLs such as [media]http://site.com/something (data).mp3[/media] will not match the next regex, so fix them first */
|
||||
preg_match_all( "/\[media\](.+?)\[\/media\]/is", $value, $matches );
|
||||
|
||||
foreach( $matches[1] as $k => $m )
|
||||
{
|
||||
$c = count( $urls );
|
||||
$urls[ $c ] = "<a href='{$m}'>{$m}</a>";
|
||||
|
||||
$value = str_replace( $matches[0][ $k ], '<!--url{' . $c . '}-->', $value );
|
||||
}
|
||||
|
||||
/* Parse standard URLs */
|
||||
preg_match_all( '#(?:^|\s|\)|\(|\{|\}|/>|>|\]|\[|;|href=\S)((http|https|news|ftp)://(?:[^<>\)\[\"\s]+|[a-zA-Z0-9/\._\-!&\#;,%\+\?:=]+))#is', $value, $matches );
|
||||
|
||||
$done = array();
|
||||
|
||||
foreach( $matches[1] as $m )
|
||||
{
|
||||
if( in_array( $m, $done ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$done[] = $m;
|
||||
|
||||
$me = null;
|
||||
|
||||
/* If this was an image URL that was not already embedded, we shouldn't try to embed it now - also this causes timeouts in
|
||||
@@ -770,15 +771,16 @@ class _LegacyParser
|
||||
}
|
||||
catch( \Exception $e ){}
|
||||
}
|
||||
|
||||
|
||||
if( $me )
|
||||
{
|
||||
$embedCount++;
|
||||
$value = str_replace( $m, $me, $value );
|
||||
|
||||
$value = preg_replace( '/' . preg_quote( $m, '/' ) . '/i', $me, $value, 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = str_replace( $m, "<a href='{$m}'>{$m}</a>", $value );
|
||||
$value = preg_replace( '/' . preg_quote( $m, '/' ) . '/i', "<a href='{$m}'>{$m}</a>", $value, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user