Version 4.1.2

This commit is contained in:
Neo committed 2025-12-19 05:32:19 -08:00
1 parent 3ba79295ee
commit 28bd025b35
1131 files changed
+63658 -20579

No files matched your search

+50 -13
View File
@@ -162,27 +162,27 @@ class _LegacyParser
$this->itemClass = $itemClass;
/* Grab legacy custom bbcodes */
if( \IPS\Db::i()->checkForTable('custom_bbcode') )
try
{
$this->bbcodes = iterator_to_array( \IPS\Db::i()->select( '*', 'custom_bbcode' )->setKeyField( 'bbcode_tag' ) );
}
else
catch( \IPS\Db\Exception $e )
{
$this->bbcodes = array();
}
/* Grab emoticons */
if( \IPS\Db::i()->checkForTable('core_emoticons') )
try
{
$this->emoticons = iterator_to_array( \IPS\Db::i()->select( '*', 'core_emoticons' )->setKeyField( 'typed' ) );
}
else
catch( \IPS\Db\Exception $e )
{
$this->emoticons = array();
}
/* Grab a new parser object */
$this->parser = new \IPS\Text\Parser( TRUE, $this->idOne ? array( $this->idOne, $this->idTwo, $this->idThree ) : NULL, $this->member, $this->attachClass, TRUE, ( $this->allowHtml ? FALSE : TRUE ), NULL );
$this->parser = new \IPS\Text\Parser( TRUE, $this->idOne ? array( $this->idOne, $this->idTwo, $this->idThree ) : NULL, $this->member, $this->attachClass, TRUE, ( $this->allowHtml ? FALSE : TRUE ), NULL, 1 );
$updatedBbcodeTags = array_keys( $this->parser->bbcodeTags( $this->member, TRUE ) );
@@ -201,11 +201,11 @@ class _LegacyParser
if( $this->media === null )
{
if( \IPS\Db::i()->checkForTable('bbcode_mediatag') )
try
{
$this->media = iterator_to_array( \IPS\Db::i()->select( '*', 'bbcode_mediatag' ) );
}
else
catch( \IPS\Db\Exception $e )
{
$this->media = array();
}
@@ -220,6 +220,29 @@ class _LegacyParser
*/
public function parse( $value )
{
/* We have to fix up newlines a little bit */
$value = str_replace( array( "\r\n", "\r" ), "\n", $value );
if ( ! \strstr( $value, "\n" ) && ( \stristr( $value, '<br>' ) || \stristr( $value, '<br />' ) ) )
{
$value = \str_ireplace( array( '<br>', '<br />' ), "\n", $value );
}
else
{
if ( \stristr( $value, '<br>' ) || \stristr( $value, '<br />' ) )
{
$value = \str_replace( "\n", "", $value );
}
}
$value = nl2br( $value );
/* In case the content rebuild has ran or partially ran on this content... */
$value = preg_replace( '#<([^>]+?)(href|src)=(\'|")<fileStore\.([\d\w\_]+?)>/#i', '<\1\2=\3%7BfileStore.\4%7D/', $value );
$value = preg_replace( '#<([^>]+?)(href|src)=(\'|")<___base_url___>/#i', '<\1\2=\3%7B___base_url___%7D/', $value );
$value = preg_replace( '#<([^>]+?)(data-fileid)=(\'|")<___base_url___>/#i', '<\1\2=\3%7B___base_url___%7D/', $value );
/* Start with legacy emoticon parsing */
$value = str_replace( "<#EMO_DIR#>", "&lt;#EMO_DIR&gt;", $value );
$value = preg_replace( "#(\s)?<([^>]+?)emoid=\"(.+?)\"([^>]*?)".">(\s)?#is", "\\1\\3\\5", $value );
@@ -248,7 +271,7 @@ class _LegacyParser
{
$code = str_replace( '<', '&lt;', str_replace( '>', '&gt;', $emoticon['typed'] ) );
if( !\stristr( $value, $code ) )
if( !$code or !\stristr( $value, $code ) )
{
continue;
}
@@ -343,7 +366,7 @@ class _LegacyParser
$value = str_ireplace( "?>" , "?&gt;" , $value );
/* Fix bbcode attributes */
$value = preg_replace_callback( "/\[(.+?)=(\"|'|&#39;|&#039;|&quot;)(.+?)(\"|'|&#39;|&#039;|&quot;)\]/", function( $matches ) {
$value = preg_replace_callback( "/\[([^\]]+?)=(\"|'|&#39;|&#039;|&quot;)([^\]]+?)(\"|'|&#39;|&#039;|&quot;)\]/", function( $matches ) {
/* We strip the enclosing quotes and we strip any trailing ';' */
return "[" . $matches[1] . "=" . rtrim( $matches[3], ';' ) . "]";
}, $value );
@@ -594,9 +617,9 @@ class _LegacyParser
$replacement = '<!--url{' . $c . '}-->';
/* In 3.x, hyperlinked YouTube URLs did replace as long as a data attribute wasn't present */
if( ! mb_strpos( $matches[1][ $k ], \IPS\Settings::i()->base_url ) AND mb_strpos( $matches[0][ $k ], 'youtube.co' ) and ! mb_strpos( $matches[0][ $k ], 'nomediaparse' ) AND \IPS\Text\Parser::embeddableMedia( $matches[1][ $k ], TRUE ) )
if( ! mb_strpos( $matches[1][ $k ], \IPS\Settings::i()->base_url ) AND mb_strpos( $matches[0][ $k ], 'youtube.co' ) and ! mb_strpos( $matches[0][ $k ], 'nomediaparse' ) AND $response = \IPS\Text\Parser::embeddableMedia( $matches[1][ $k ], TRUE ) )
{
$replacement = $matches[1][ $k ];
$urls[ $c ] = $response;
}
$value = str_replace( $m, $replacement, $value );
@@ -614,7 +637,7 @@ class _LegacyParser
}
/* Parse standard URLs */
preg_match_all( '#((http|https|news|ftp)://(?:[^<>\)\[\"\s]+|[a-zA-Z0-9/\._\-!&\#;,%\+\?:=]+))#is', $value, $matches );
preg_match_all( '#(?:^|\s|\)|\(|\{|\}|/>|>|\]|\[|;|href=\S)((http|https|news|ftp)://(?:[^<>\)\[\"\s]+|[a-zA-Z0-9/\._\-!&\#;,%\+\?:=]+))#is', $value, $matches );
$done = array();
@@ -682,7 +705,7 @@ class _LegacyParser
if( $attachment['attach_is_image'] )
{
$attachment['attach_thumb_location'] = $attachment['attach_thumb_location'] ?: $attachment['attach_location'];
$return = "<a class='ipsAttachLink ipsAttachLink_image' href='{fileStore.core_Attachment}/{$attachment['attach_location']}'><img class='ipsImage ipsImage_thumbnailed' src='{fileStore.core_Attachment}/{$attachment['attach_thumb_location']}' data-fileid='" . \IPS\Settings::i()->base_url . "applications/core/interface/file/attachment.php?id={$attachment['attach_id']}'></a>";
$return = "<a class='ipsAttachLink ipsAttachLink_image' href='{fileStore.core_Attachment}/{$attachment['attach_location']}'><img src='{fileStore.core_Attachment}/{$attachment['attach_thumb_location']}' data-fileid='" . \IPS\Settings::i()->base_url . "applications/core/interface/file/attachment.php?id={$attachment['attach_id']}'></a>";
}
else
{
@@ -793,6 +816,12 @@ class _LegacyParser
return "<pre class='ipsCode " . implode( ' ', $newClasses ) . "'>";
}, $value );
/* Put the dynamic replacements back now */
$value = preg_replace( '#<([^>]+?)(href|src|srcset)=(\'|")%7BfileStore\.([\d\w\_]+?)%7D/#i', '<\1\2=\3<fileStore.\4>/', $value );
$value = preg_replace( '#<([^>]+?)(srcset)=(\'|")%7BfileStore\.([\d\w\_]+?)%7D/#i', '<\1\2=\3<fileStore.\4>/', $value );
$value = preg_replace( '#<([^>]+?)(href|src|srcset)=(\'|")%7B___base_url___%7D/#i', '<\1\2=\3<___base_url___>/', $value );
$value = preg_replace( '#<([^>]+?)(data-fileid)=(\'|")%7B___base_url___%7D/#i', '<\1\2=\3<___base_url___>/', $value );
//print htmlspecialchars( $value );print "<hr style='color:red;'>";print $value;print "<hr style='color:red;'>";
/* Return */
@@ -803,6 +832,14 @@ class _LegacyParser
$result = $this->parser->parse( $value );
/* If they are not using UTF8MB4, we need to convert emoji back to html entities as HTMLPurifier will have converted them on us */
if ( \IPS\Settings::i()->getFromConfGlobal('sql_utf8mb4') !== TRUE )
{
$result = preg_replace_callback( '/[\x{10000}-\x{10FFFF}]/u', function( $mb4Character ) {
return mb_convert_encoding( $mb4Character[0], 'HTML-ENTITIES', 'UTF-8' );
}, $result );
}
/* URLs that are turned into embeds end up as <a href=''><iframe ...></a> */
$result = preg_replace( "/\<a href=[\"']{2}.*?\>(?:&gt;)?(\<iframe.+?\>)\<\/a\>/i", "$1", $result );