Version 5.0.6

This commit is contained in:
Neo committed 2025-12-19 18:55:49 -08:00
1 parent a3a4a9ccbd
commit b89858b2ff
1214 files changed
+92828 -14859

No files matched your search

+16 -16
View File
@@ -59,7 +59,7 @@ class ConverterParser extends Parser
/**
* @brief If parsing BBCode, the supported BBCode tags
*/
protected ?array $bbcode = NULL;
public ?array $bbcodes = NULL;
/**
* Constructor
@@ -89,7 +89,7 @@ class ConverterParser extends Parser
/* Get available BBCodes */
if ( $bbcode )
{
$this->bbcode = static::bbcodeTags( $this->member, $this->area );
$this->bbcodes = static::bbcodeTags( $this->member, $this->area );
}
/* Get attachments */
@@ -173,11 +173,11 @@ class ConverterParser extends Parser
if( $enabled )
{
$this->bbcode = static::bbcodeTags( $this->member, $this->area );
$this->bbcodes = static::bbcodeTags( $this->member, $this->area );
}
else
{
$this->bbcode = NULL;
$this->bbcodes = NULL;
}
}
}
@@ -234,10 +234,10 @@ class ConverterParser extends Parser
/* This fix resolves an issue using <br> mode where BBCode tags are wrapped in P tags like so: <p>[tag]</p><p>Content</p><p>[/tag]</p> tags.
The fix just removes the </p><p> tags inside block BBCode tags, so our example ends up parsing like so: <p>[tag]<br><br>Content<br><br>[/tag]</p>
We will want to find a more elegant fix for this at some point */
if ( $this->bbcode !== NULL and ! Settings::i()->editor_paragraph_padding )
if ( $this->bbcodes !== NULL and ! Settings::i()->editor_paragraph_padding )
{
$blockTags = array();
foreach( $this->bbcode as $tag => $data )
foreach( $this->bbcodes as $tag => $data )
{
if ( ! empty( $data['block'] ) )
{
@@ -288,7 +288,7 @@ class ConverterParser extends Parser
$document = $parser->parseValueIntoDocument( $value );
/* [page] tags need to be handled specially */
if ( $this->bbcode !== NULL and $this->containsPageTags )
if ( $this->bbcodes !== NULL and $this->containsPageTags )
{
$body = DOMParser::getDocumentBody( $document );
@@ -443,10 +443,10 @@ class ConverterParser extends Parser
}
/* If we are parsing BBCode, we will look for opening (e.g. "[foo=bar]") and closing (e.g. "[/foo]") tags */
if ( $this->bbcode !== NULL and count( $this->bbcode ) )
if ( $this->bbcodes !== NULL and count( $this->bbcodes ) )
{
/* First, if we have any single-tag BBCodes (e.g. "[img=URL]") expressed as normal BBCodes (e.g. "[img]URL[/img]") - fix that */
foreach ( $this->bbcode as $tag => $bbcode )
foreach ( $this->bbcodes as $tag => $bbcode )
{
if ( isset( $bbcode['single'] ) and $bbcode['single'] )
{
@@ -462,7 +462,7 @@ class ConverterParser extends Parser
}
/* And add our regex to the breakpoints */
$breakPoints[] = '(\[\/?(?:' . implode( '|', array_map( function ( $value ) { return preg_quote( $value, '/' ); }, array_keys( $this->bbcode ) ) ) . ')(?:[=\s].+?)?\])';
$breakPoints[] = '(\[\/?(?:' . implode( '|', array_map( function ( $value ) { return preg_quote( $value, '/' ); }, array_keys( $this->bbcodes ) ) ) . ')(?:[=\s].+?)?\])';
}
/* If we have any acronyms, they also need to be breakpoints */
@@ -522,10 +522,10 @@ class ConverterParser extends Parser
/* Start of BBCode tag? */
if (
$this->bbcode !== NULL and $this->bbcodeParse and // BBCode is enabled
$this->bbcodes !== NULL and $this->bbcodeParse and // BBCode is enabled
preg_match( '/^\[([a-z\*]+?)(?:([=\s])(.+?))?\]$/i', $section, $matches ) and // It looks like a BBCode tag
array_key_exists( mb_strtolower( $matches[1] ), $this->bbcode ) and // The tag is in the list
( !isset( $this->bbcode[ mb_strtolower( $matches[1] ) ]['allowOption'] ) or $this->bbcode[ mb_strtolower( $matches[1] ) ]['allowOption'] === TRUE or !isset( $matches[3] ) or !$matches[3] ) // If options aren't allowed for this tag, there isn't one
array_key_exists( mb_strtolower( $matches[1] ), $this->bbcodes ) and // The tag is in the list
( !isset( $this->bbcodes[ mb_strtolower( $matches[1] ) ]['allowOption'] ) or $this->bbcodes[ mb_strtolower( $matches[1] ) ]['allowOption'] === TRUE or !isset( $matches[3] ) or !$matches[3] ) // If options aren't allowed for this tag, there isn't one
)
{
/* What was the option? */
@@ -689,7 +689,7 @@ class ConverterParser extends Parser
protected function _openBBCode( string $tag, ?string $option, DOMNode &$parent, int $sectionId, int $sectionCount ) : void
{
/* Get definition */
$bbcode = $this->bbcode[ $tag ];
$bbcode = $this->bbcodes[ $tag ];
/* Get the document */
$document = $parent->ownerDocument ?: $parent;
@@ -744,7 +744,7 @@ class ConverterParser extends Parser
if ( $bbcodeElement instanceof DOMElement )
{
if ( $lastOpenedBlockId and list( $id, $tagName ) = explode( '-', $lastOpenedBlockId ) and isset( $this->bbcode[ $tagName ]['noChildren'] ) and $this->bbcode[ $tagName ]['noChildren'] )
if ( $lastOpenedBlockId and list( $id, $tagName ) = explode( '-', $lastOpenedBlockId ) and isset( $this->bbcodes[ $tagName ]['noChildren'] ) and $this->bbcodes[ $tagName ]['noChildren'] )
{
$parent->appendChild( $bbcodeElement );
}
@@ -815,7 +815,7 @@ class ConverterParser extends Parser
protected function _closeBBCode( string $tag, DOMNode &$parent, int $sectionId, int $sectionCount ) : void
{
/* Get definition */
$bbcode = $this->bbcode[ $tag ];
$bbcode = $this->bbcodes[ $tag ];
/* Block level? */
if ( isset( $bbcode['block'] ) and $bbcode['block'] )
+3 -3
View File
@@ -75,7 +75,7 @@ class LegacyParser
/**
* @brief BBcodes
*/
public static ?array $bbcodes = NULL;
public ?array $bbcodes = NULL;
/**
* @brief Emoticons
@@ -187,7 +187,7 @@ class LegacyParser
/* Grab legacy custom bbcodes */
try
{
$this->bbcodes = iterator_to_array( Db::i()->select( '*', 'custom_bbcode' )->setKeyField( 'bbcode_tag' ) );
$this->bbcodes = iterator_to_array( Db::i()->select( '*', 'convert_custom_bbcode' )->setKeyField( 'bbcode_tag' ) );
}
catch(Db\Exception $e )
{
@@ -484,7 +484,7 @@ class LegacyParser
foreach( $this->parser->bbcodes as $code )
{
/* If we don't have a regex replacement, probably because we used to use a plugin, we can't do this automatically */
if( !$code['bbcode_replace'] )
if( !isset( $code['bbcode_replace'] ) or !$code['bbcode_replace'] )
{
continue;
}
+42 -3
View File
@@ -56,6 +56,7 @@ use IPS\Xml\DOMDocument;
use OutOfRangeException;
use UnderflowException;
use UnexpectedValueException;
use function array_key_exists;
use function chr;
use function count;
use function defined;
@@ -641,6 +642,7 @@ class Parser
$def->addAttribute( 'iframe', 'data-ipsembed-timestamp', 'Text' ); // used in embeddableMedia
$def->addAttribute( 'iframe', 'data-internalembed', 'Text' ); // used in embeddableMedia
$def->addAttribute( 'iframe', 'allowfullscreen', 'Text' ); // Some services will specify this property
$def->addAttribute( 'iframe', 'allow', 'Text' ); // Some services will specify this property. We replace it with individual allow* attributes later on in the parsing process
/* Custom Iframes need these */
$def->addAttribute( 'iframe', 'width', 'Number' ); // Some services will specify this property
@@ -681,14 +683,14 @@ class Parser
$def->addAttribute( 'iframe', 'data-munge-src', 'Text' );
/* Videos */
$def->addElement( 'video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array(
$def->addElement( 'video', 'Inline', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array(
'controls' => 'Bool',
'data-controller' => new HTMLPurifier_AttrDef_Enum( array( 'core.global.core.embeddedvideo' ) ),
'data-video-embed' => 'Text',
'preload' => new HTMLPurifier_AttrDef_Enum( [ 'auto', 'metadata', 'none' ] ),
'style' => 'Text'
) );
$def->addElement( 'source', 'Block', 'Flow', 'Common', array(
$def->addElement( 'source', 'Inline', 'Flow', 'Common', array(
'src' => new HTMLPurifier_AttrDef_URI( TRUE ),
'srcset' => new HtmlPurifierSrcsetDef( TRUE ),
'media' => 'Text',
@@ -697,7 +699,7 @@ class Parser
) );
/* Audio */
$def->addElement('audio', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array(
$def->addElement('audio', 'Inline', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array(
'controls' => 'Bool',
'data-controller' => new HTMLPurifier_AttrDef_Enum( array( 'core.global.core.embeddedaudio' ) ),
'src' => new HTMLPurifier_AttrDef_URI( TRUE ),
@@ -1777,6 +1779,43 @@ class Parser
}
}
catch ( Url\Exception ) {}
}
/* It is possible the iframe has an `allow` property. Let's make sure to split that up into individual attributes */
if ( $element->hasAttribute( "allow" ) )
{
// todo support a system setting for this in v5.x
$allowedAttrs = [
"fullscreen" => "",
"picture-in-picture" => "",
'encrypted-media' => '',
];
$foundAttrs = [];
foreach ( explode( ";", $element->getAttribute( 'allow' ) ) as $permission )
{
$fixedPermission = mb_strtolower( trim( $permission ) );
if ( array_key_exists( $fixedPermission, $allowedAttrs ) )
{
$foundAttrs[] = $fixedPermission;
}
}
if ( $element->hasAttribute( 'allowfullscreen' ) )
{
$foundAttrs[] = "fullscreen";
$element->removeAttribute( "allowfullscreen" );
}
if ( count( $foundAttrs ) )
{
$element->setAttribute( "allow", implode( "; ", array_unique( $foundAttrs ) ) );
}
else
{
$element->removeAttribute( "allow" );
}
}
/* Native Lazyload all iFrames */