Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -12,16 +12,34 @@
namespace IPS\convert\Software\Forums;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use Exception;
use IPS\Content;
use IPS\convert\Software;
use IPS\convert\Software\Core\Mybb;
use IPS\Db;
use IPS\Http\Url;
use IPS\Member;
use IPS\Node\Model;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Request;
use IPS\Task;
use OutOfRangeException;
use UnderflowException;
use function defined;
use function preg_match;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* MyBB Forums Converter
*/
class _Mybb extends \IPS\convert\Software
class Mybb extends Software
{
/**
* Software Name
@@ -121,10 +139,10 @@ class _Mybb extends \IPS\convert\Software
/* Get our reactions to let the admin map them */
$options = array();
$descriptions = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_reactions' ), 'IPS\Content\Reaction' ) AS $reaction )
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'core_reactions' ), 'IPS\Content\Reaction' ) AS $reaction )
{
$options[ $reaction->id ] = $reaction->_icon->url;;
$descriptions[ $reaction->id ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id ) . '<br>' . $reaction->_description;
$options[ $reaction->id ] = $reaction->_icon->url;
$descriptions[ $reaction->id ] = Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id ) . '<br>' . $reaction->_description;
}
$return['convertForumsPosts'] = array(
@@ -154,8 +172,8 @@ class _Mybb extends \IPS\convert\Software
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack('convert_mybb_attach_path'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
'field_hint' => Member::loggedIn()->language()->addToStack('convert_mybb_attach_path'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
),
);
break;
@@ -172,31 +190,33 @@ class _Mybb extends \IPS\convert\Software
public function finish()
{
/* Content Rebuilds */
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\forums\Forum', 'count' => 0 ), 4, array( 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'forums_posts', 'class' => 'IPS\forums\Topic\Post' ), 2, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\forums\Topic' ), 3, array( 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildFirstPostIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
\IPS\Task::queue( 'convert', 'DeleteEmptyTopics', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\forums\Forum', 'count' => 0 ), 4, array( 'class' ) );
Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'forums_posts', 'class' => 'IPS\forums\Topic\Post' ), 2, array( 'app', 'link', 'class' ) );
Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\forums\Topic' ), 3, array( 'class' ) );
Task::queue( 'convert', 'RebuildFirstPostIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
Task::queue( 'convert', 'DeleteEmptyTopics', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
/* Rebuild Leaderboard */
\IPS\Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
\IPS\Db::i()->delete('core_reputation_leaderboard_history');
Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
Db::i()->delete('core_reputation_leaderboard_history');
/* Caches */
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'forums_topics', 'class' => 'IPS\forums\Topic' ), 3, array( 'app', 'link', 'class' ) );
Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'forums_topics', 'class' => 'IPS\forums\Topic' ), 3, array( 'app', 'link', 'class' ) );
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics", "f_topic_tags_recount" );
}
/**
* Fix Post Data
* Pre-process content for the Invision Community text parser
*
* @param string $post Post
* @return string Fixed Post
* @param string The post
* @param string|null Content Classname passed by post-conversion rebuild
* @param int|null Content ID passed by post-conversion rebuild
* @return string The converted post
*/
public static function fixPostData( $post )
public static function fixPostData( string $post, ?string $className=null, ?int $contentId=null ): string
{
return \IPS\convert\Software\Core\Mybb::fixPostData( $post );
return Mybb::fixPostData( $post, $className, $contentId );
}
/**
@@ -345,7 +365,7 @@ class _Mybb extends \IPS\convert\Software
);
}
}
catch( \UnderflowException $e ) {} # if the poll is missing, don't bother
catch( UnderflowException $e ) {} # if the poll is missing, don't bother
}
/* Moved ?*/
@@ -360,7 +380,7 @@ class _Mybb extends \IPS\convert\Software
$this->db->select( 'fid', 'threads', array( "tid=?", $moved[1] ) )->first()
);
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
$moved_to = NULL;
}
@@ -408,7 +428,7 @@ class _Mybb extends \IPS\convert\Software
'tag_prefix' => 1,
) );
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
}
/* Follows */
@@ -566,7 +586,7 @@ class _Mybb extends \IPS\convert\Software
{
$topic_id = $this->db->select( 'tid', 'posts', array( "pid=?", $row['pid'] ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
/* Post is orphaned */
$libraryClass->setLastKeyValue( $row['aid'] );
@@ -600,17 +620,17 @@ class _Mybb extends \IPS\convert\Software
{
$pid = $this->app->getLink( $row['pid'], 'forums_posts' );
$post = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
$post = Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
if( \preg_match( '#\[attachment=' . $row['aid'] . ']#i', $post ) )
if( preg_match( '#\[attachment=' . $row['aid'] . ']#i', $post ) )
{
$post = str_ireplace( '[attachment=' . $row['aid'] . ']', '[attachment=' . $attachId . ':name]', $post );
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
}
}
}
catch( \UnderflowException $e ) {}
catch( \OutOfRangeException $e ) {}
catch( UnderflowException $e ) {}
catch( OutOfRangeException $e ) {}
$libraryClass->setLastKeyValue( $row['aid'] );
}
@@ -619,23 +639,23 @@ class _Mybb extends \IPS\convert\Software
/**
* Check if we can redirect the legacy URLs from this software to the new locations
*
* @return NULL|\IPS\Http\Url
* @return NULL|Url
*/
public function checkRedirects()
{
$url = \IPS\Request::i()->url();
$url = Request::i()->url();
if( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'showthread.php' ) !== FALSE )
if( mb_strpos( $url->data[ Url::COMPONENT_PATH ], 'showthread.php' ) !== FALSE )
{
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
$oldId = \IPS\Request::i()->tid;
$oldId = Request::i()->tid;
}
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'forumdisplay.php' ) !== FALSE )
elseif( mb_strpos( $url->data[ Url::COMPONENT_PATH ], 'forumdisplay.php' ) !== FALSE )
{
$class = '\IPS\forums\Forum';
$types = array( 'forums', 'forums_forums' );
$oldId = \IPS\Request::i()->fid;
$oldId = Request::i()->fid;
}
if( isset( $class ) )
@@ -646,20 +666,20 @@ class _Mybb extends \IPS\convert\Software
{
$data = (string) $this->app->getLink( $oldId, $types );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$data = (string) $this->app->getLink( $oldId, $types, FALSE, TRUE );
}
$item = $class::load( $data );
if( $item instanceof \IPS\Content )
if( $item instanceof Content )
{
if( $item->canView() )
{
return $item->url();
}
}
elseif( $item instanceof \IPS\Node\Model )
elseif( $item instanceof Model )
{
if( $item->can( 'view' ) )
{
@@ -667,7 +687,7 @@ class _Mybb extends \IPS\convert\Software
}
}
}
catch( \Exception $e )
catch( Exception $e )
{
return NULL;
}