Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Text;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -23,7 +23,7 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
class _LegacyParser
|
||||
{
|
||||
/**
|
||||
* Maximum number of embeds we will try.
|
||||
* @brief Maximum number of embeds we will try.
|
||||
* @note Attempting to pull too many during the rebuild process can easily time out
|
||||
*/
|
||||
public $maxEmbeds = 10;
|
||||
@@ -44,7 +44,7 @@ class _LegacyParser
|
||||
*/
|
||||
public static function parseStatic( $value, $member=NULL, $allowHtml=FALSE, $attachClass=null, $id1=0, $id2=0, $id3=NULL, $itemClass=NULL )
|
||||
{
|
||||
$obj = new self( $member, $allowHtml, $attachClass, $id1, $id2, $id3, $itemClass );
|
||||
$obj = new static( $member, $allowHtml, $attachClass, $id1, $id2, $id3, $itemClass );
|
||||
return $obj->parse( $value );
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class _LegacyParser
|
||||
{
|
||||
foreach( static::$bbcodes as $code )
|
||||
{
|
||||
if( $code['bbcode_tag'] == $bbcode OR ( $code['bbcode_aliases'] AND in_array( $bbcode, explode( ',', $code['bbcode_aliases'] ) ) ) )
|
||||
if( $code['bbcode_tag'] == $bbcode OR ( $code['bbcode_aliases'] AND \in_array( $bbcode, explode( ',', $code['bbcode_aliases'] ) ) ) )
|
||||
{
|
||||
if( $code['bbcode_groups'] == 'all' )
|
||||
{
|
||||
@@ -175,9 +175,27 @@ class _LegacyParser
|
||||
$this->emoticons = array();
|
||||
}
|
||||
|
||||
/* The `a_type` column is added in 4.5, so we need to account for this if running the legacy parser during an older upgrade */
|
||||
$newAcronyms = \IPS\Db::i()->checkForColumn( 'core_acronyms', 'a_type' );
|
||||
|
||||
/* Grab a new parser object */
|
||||
\IPS\Text\Parser::$requestTimeout = 1;
|
||||
$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, $newAcronyms );
|
||||
|
||||
/* If we're in the upgrader and the new acronym support hasn't been added yet, populate acronyms manually */
|
||||
if( !$newAcronyms )
|
||||
{
|
||||
$this->parser->caseSensitiveAcronyms = iterator_to_array( \IPS\Db::i()->select( array( 'a_short', 'a_long', "'acronym' as `a_type`" ), 'core_acronyms', array( 'a_casesensitive=1' ) )->setKeyField( 'a_short' ) );
|
||||
|
||||
$this->parser->caseInsensitiveAcronyms = array();
|
||||
foreach ( \IPS\Db::i()->select( array( 'a_short', 'a_long', "'acronym' as `a_type`" ), 'core_acronyms', array( 'a_casesensitive=0' ) )->setKeyField( 'a_short' ) as $k => $v )
|
||||
{
|
||||
$this->parser->caseInsensitiveAcronyms[ mb_strtolower( $k ) ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
/* We need to force bbcode to parse for the legacy parser */
|
||||
$this->parser->forceBbcodeEnabled = TRUE;
|
||||
|
||||
$updatedBbcodeTags = array_keys( $this->parser->bbcodeTags( $this->member, TRUE ) );
|
||||
|
||||
@@ -255,7 +273,7 @@ class _LegacyParser
|
||||
|
||||
preg_match_all( "#(<img(?:[^>]+?)class=['\"]bbc_emoticon[\"'](?:[^>]+?)alt=['\"](.+?)[\"'](?:[^>]+?)?>)#is", $value, $matches );
|
||||
|
||||
if( is_array($matches[1]) AND count($matches[1]) )
|
||||
if( \is_array($matches[1]) AND \count($matches[1]) )
|
||||
{
|
||||
foreach( $matches[1] as $index => $match )
|
||||
{
|
||||
@@ -323,7 +341,7 @@ class _LegacyParser
|
||||
|
||||
foreach( $matches[0] as $k => $m )
|
||||
{
|
||||
$c = count( $codeboxes );
|
||||
$c = \count( $codeboxes );
|
||||
$codeboxes[ $c ] = $m;
|
||||
|
||||
$replacement = '<!--codeboxes{' . $c . '}-->';
|
||||
@@ -335,7 +353,7 @@ class _LegacyParser
|
||||
|
||||
foreach( $matches[0] as $k => $m )
|
||||
{
|
||||
$c = count( $codeboxes );
|
||||
$c = \count( $codeboxes );
|
||||
$codeboxes[ $c ] = $m;
|
||||
|
||||
$replacement = '<!--codeboxes{' . $c . '}-->';
|
||||
@@ -343,6 +361,19 @@ class _LegacyParser
|
||||
$value = str_replace( $m, $replacement, $value );
|
||||
}
|
||||
|
||||
preg_match_all( "/\<table([^>]*?)>(.+?)\<\/table\>/ims", $value, $matches );
|
||||
|
||||
$tables = array();
|
||||
foreach( $matches[0] as $k => $m )
|
||||
{
|
||||
$c = \count( $tables );
|
||||
$tables[ $c ] = \str_ireplace( '<td><br />', '<td>', $m ); // Fix up un-needed BRs added earlier in this method
|
||||
|
||||
$replacement = '<!--tables{' . $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 );
|
||||
@@ -471,6 +502,9 @@ class _LegacyParser
|
||||
}
|
||||
}
|
||||
|
||||
/* Really really old versions of IPB used to use [attachmentid=X] as markers for attachments */
|
||||
$value = preg_replace( "/\[attachmentid=(.+?)\]/i", "[attachment=$1:name]", $value );
|
||||
|
||||
/* Figure out what attachments are missing so we can add them at the end */
|
||||
if( $this->attachClass !== NULL AND $this->idOne !== 0 )
|
||||
{
|
||||
@@ -478,7 +512,7 @@ class _LegacyParser
|
||||
|
||||
preg_match_all( "/\[attachment=(.+?):(.+?)\]/ims", $value, $matches );
|
||||
|
||||
if( count( $matches[1] ) )
|
||||
if( \count( $matches[1] ) )
|
||||
{
|
||||
foreach( $matches[1] as $id )
|
||||
{
|
||||
@@ -497,7 +531,7 @@ class _LegacyParser
|
||||
|
||||
foreach( $mappedAttachments as $attachmentId => $map )
|
||||
{
|
||||
if( !in_array( $attachmentId, $embeddedAttachments ) )
|
||||
if( !\in_array( $attachmentId, $embeddedAttachments ) )
|
||||
{
|
||||
$value .= '<p>[attachment=' . $attachmentId . ':name]</p>';
|
||||
}
|
||||
@@ -546,7 +580,7 @@ class _LegacyParser
|
||||
try
|
||||
{
|
||||
$album = \IPS\gallery\Album::constructFromData( \IPS\Db::i()->select( '*', 'gallery_albums', array( 'album_id=?', (int) $matches[3] ) )->first() );
|
||||
return \IPS\Text\Parser::embeddableMedia( \IPS\Http\Url::createFromString( $album->url(), TRUE, TRUE ) );
|
||||
return \IPS\Text\Parser::embeddableMedia( \IPS\Http\Url::createFromString( $album->url(), TRUE, TRUE ), FALSE, $this->member );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
@@ -700,7 +734,7 @@ class _LegacyParser
|
||||
$url = preg_replace( "/#entry(\d+)/", $sep . "do=findComment&comment=$1", $url );
|
||||
}
|
||||
|
||||
$c = count( $urls );
|
||||
$c = \count( $urls );
|
||||
$urls[ $c ] = str_replace( $matches[1][ $k ], $url, $m );
|
||||
|
||||
$replacement = '<!--url{' . $c . '}-->';
|
||||
@@ -708,7 +742,7 @@ class _LegacyParser
|
||||
try
|
||||
{
|
||||
/* 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' ) OR mb_strpos( $matches[0][ $k ], 'youtu.be' ) ) and ! mb_strpos( $matches[0][ $k ], 'nomediaparse' ) AND $response = \IPS\Text\Parser::embeddableMedia( \IPS\Http\Url::createFromString( $matches[1][ $k ], FALSE, TRUE ) ) )
|
||||
if( ! mb_strpos( $matches[1][ $k ], \IPS\Settings::i()->base_url ) AND ( mb_strpos( $matches[0][ $k ], 'youtube.co' ) OR mb_strpos( $matches[0][ $k ], 'youtu.be' ) ) and ! mb_strpos( $matches[0][ $k ], 'nomediaparse' ) AND $response = \IPS\Text\Parser::embeddableMedia( \IPS\Http\Url::createFromString( $matches[1][ $k ], FALSE, TRUE ), FALSE, $this->member ) )
|
||||
{
|
||||
$urls[ $c ] = $response;
|
||||
}
|
||||
@@ -723,7 +757,7 @@ class _LegacyParser
|
||||
|
||||
foreach( $matches[0] as $m )
|
||||
{
|
||||
$c = count( $urls );
|
||||
$c = \count( $urls );
|
||||
$urls[ $c ] = $m;
|
||||
|
||||
$value = str_replace( $m, '<!--url{' . $c . '}-->', $value );
|
||||
@@ -734,7 +768,7 @@ class _LegacyParser
|
||||
|
||||
foreach( $matches[1] as $k => $m )
|
||||
{
|
||||
$c = count( $urls );
|
||||
$c = \count( $urls );
|
||||
$urls[ $c ] = "<a href='{$m}'>{$m}</a>";
|
||||
|
||||
$value = str_replace( $matches[0][ $k ], '<!--url{' . $c . '}-->', $value );
|
||||
@@ -767,7 +801,7 @@ class _LegacyParser
|
||||
|
||||
try
|
||||
{
|
||||
$me = \IPS\Text\Parser::embeddableMedia( \IPS\Http\Url::createFromString( $url, FALSE, TRUE ) );
|
||||
$me = \IPS\Text\Parser::embeddableMedia( \IPS\Http\Url::createFromString( $url, FALSE, TRUE ), FALSE, $this->member );
|
||||
}
|
||||
catch( \Exception $e ){}
|
||||
}
|
||||
@@ -777,7 +811,7 @@ class _LegacyParser
|
||||
$embedCount++;
|
||||
}
|
||||
|
||||
$c = count( $urls );
|
||||
$c = \count( $urls );
|
||||
$urls[ $c ] = $me ?: "<a href='{$m}'>{$m}</a>";
|
||||
|
||||
$value = str_replace( $matches[1][ $k ], '<!--url{' . $c . '}-->', $value );
|
||||
@@ -888,6 +922,11 @@ class _LegacyParser
|
||||
{
|
||||
$value = str_replace( '<!--codeboxes{' . $k . '}-->', $v, $value );
|
||||
}
|
||||
/* Put tables back */
|
||||
foreach( $tables as $k => $v )
|
||||
{
|
||||
$value = str_replace( '<!--tables{' . $k . '}-->', $v, $value );
|
||||
}
|
||||
|
||||
/* Block level tags */
|
||||
$value = preg_replace( "/\[(code|codebox|sql|php|xml|html)(.*?)\](.+?)\[\/(code|codebox|sql|php|xml|html)\]/ims", "</p><div>[$1$2]$3[/$4]</div><p>", $value );
|
||||
@@ -950,7 +989,7 @@ class _LegacyParser
|
||||
/**
|
||||
* Parse new quotes
|
||||
*
|
||||
* @param array Data from preg_replace callback
|
||||
* @param array $matches Data from preg_replace callback
|
||||
* @return string Converted text
|
||||
*/
|
||||
protected function _parseOldQuote( $matches=array() )
|
||||
@@ -972,7 +1011,7 @@ class _LegacyParser
|
||||
|
||||
if ( $match[1] )
|
||||
{
|
||||
$return[] = " post='" . intval($match[1]) . "'";
|
||||
$return[] = " post='" . \intval($match[1]) . "'";
|
||||
}
|
||||
|
||||
if ( $match[2] )
|
||||
@@ -987,14 +1026,14 @@ class _LegacyParser
|
||||
/**
|
||||
* Parse new quotes #2
|
||||
*
|
||||
* @param array Data from preg_replace callback
|
||||
* @param array $matches Data from preg_replace callback
|
||||
* @return string Converted text
|
||||
*/
|
||||
protected function _parseOldBlockquote( $matches=array() )
|
||||
{
|
||||
$parameters = array( 'data-ipsQuote' => '', 'class' => 'ipsQuote' );
|
||||
|
||||
if( count( $matches[1] ) )
|
||||
if( \count( $matches ) )
|
||||
{
|
||||
preg_match( "/data-author=['\"](.+?)[\"']/i", static::_cleanQuoteName( $matches[1] ), $author );
|
||||
preg_match( "/data-cid=['\"](.+?)[\"']/i", $matches[1], $cid );
|
||||
@@ -1040,14 +1079,14 @@ class _LegacyParser
|
||||
/**
|
||||
* Parse new quotes #3
|
||||
*
|
||||
* @param array Data from preg_replace callback
|
||||
* @param array $matches Data from preg_replace callback
|
||||
* @return string Converted text
|
||||
*/
|
||||
protected function _parseOldQuoteBbcode( $matches=array() )
|
||||
{
|
||||
$parameters = array( 'data-ipsQuote' => '', 'class' => 'ipsQuote' );
|
||||
|
||||
if( count( $matches[1] ) )
|
||||
if( \count( $matches ) )
|
||||
{
|
||||
preg_match( "/name=['\"](.+?)[\"']/i", $matches[1], $author );
|
||||
preg_match( "/post=['\"](.+?)[\"']/i", $matches[1], $cid );
|
||||
@@ -1101,7 +1140,7 @@ class _LegacyParser
|
||||
/**
|
||||
* Convert flash HTML back into BBCode
|
||||
*
|
||||
* @param array Data from preg_replace callback
|
||||
* @param array $matches Data from preg_replace callback
|
||||
* @return string Converted text
|
||||
*/
|
||||
protected function _parseOldFlash( $matches=array() )
|
||||
@@ -1114,7 +1153,7 @@ class _LegacyParser
|
||||
/**
|
||||
* Convert old code tags back into bbcode
|
||||
*
|
||||
* @param array Data from preg_replace callback
|
||||
* @param array $matches Data from preg_replace callback
|
||||
* @return string Converted text
|
||||
*/
|
||||
protected function _parseOldCode( $matches=array() )
|
||||
@@ -1125,7 +1164,7 @@ class _LegacyParser
|
||||
/**
|
||||
* Convert download manager screenshot URLs
|
||||
*
|
||||
* @param array Data from preg_replace callback
|
||||
* @param array $matches Data from preg_replace callback
|
||||
* @return string Converted text
|
||||
*/
|
||||
protected function _fixDownloadsScreenshots( $matches )
|
||||
@@ -1152,7 +1191,7 @@ class _LegacyParser
|
||||
/**
|
||||
* Legacy names can have things like $ and ' which break new parser
|
||||
*
|
||||
* @param string Name
|
||||
* @param string $name Name
|
||||
* @return string Converted name
|
||||
*/
|
||||
protected static function _cleanQuoteName( $name )
|
||||
@@ -1164,4 +1203,4 @@ class _LegacyParser
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user