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,39 @@
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 InvalidArgumentException;
use IPS\Content;
use IPS\convert\App;
use IPS\convert\Software;
use IPS\convert\Software\Core\Xenforo;
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 count;
use function defined;
use function is_array;
use function is_null;
use function unserialize;
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;
}
/**
* Xenforo Forums Converter
*/
class _Xenforo extends \IPS\convert\Software
class Xenforo extends Software
{
use \IPS\convert\Tools\Xenforo;
@@ -43,12 +66,12 @@ class _Xenforo extends \IPS\convert\Software
/**
* Constructor
*
* @param \IPS\convert\App $app The application to reference for database and other information.
* @param App $app The application to reference for database and other information.
* @param bool $needDB Establish a DB connection
* @return void
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function __construct( \IPS\convert\App $app, $needDB=TRUE )
public function __construct( App $app, $needDB=TRUE )
{
$return = parent::__construct( $app, $needDB );
@@ -59,7 +82,7 @@ class _Xenforo extends \IPS\convert\Software
/* Is this XF1 or XF2 */
if ( static::$isLegacy === NULL )
{
$version = $this->db->select( 'MAX(version_id)', 'xf_template', array( \IPS\Db::i()->in( 'addon_id', array( 'XF', 'XenForo' ) ) ) )->first();
$version = $this->db->select( 'MAX(version_id)', 'xf_template', array( Db::i()->in( 'addon_id', array( 'XF', 'XenForo' ) ) ) )->first();
if ( $version < 2000010 )
{
@@ -79,7 +102,7 @@ class _Xenforo extends \IPS\convert\Software
}
}
}
catch( \Exception $e ) {} # If we can't query, we won't be able to do anything anyway
catch( Exception $e ) {} # If we can't query, we won't be able to do anything anyway
}
return $return;
@@ -117,7 +140,7 @@ class _Xenforo extends \IPS\convert\Software
return array(
'convertForumsForums' => array(
'table' => 'xf_node',
'where' => array( \IPS\Db::i()->in( 'node_type_id', array( 'Category', 'Forum', 'LinkForum' ) ) )
'where' => array( Db::i()->in( 'node_type_id', array( 'Category', 'Forum', 'LinkForum' ) ) )
),
'convertForumsTopics' => array(
'table' => 'xf_thread',
@@ -192,10 +215,10 @@ class _Xenforo extends \IPS\convert\Software
$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 );
$descriptions[ $reaction->id ] = Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id );
}
$return['convertForumsPosts'] = array(
@@ -219,8 +242,8 @@ class _Xenforo extends \IPS\convert\Software
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack('convert_xf_attach_path'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
'field_hint' => Member::loggedIn()->language()->addToStack('convert_xf_attach_path'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
)
);
break;
@@ -237,27 +260,29 @@ class _Xenforo 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' ) );
/* 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 Raw post data
* @return string Parsed post data
* @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\Xenforo::fixPostData( $post );
return Xenforo::fixPostData( $post, $className, $contentId );
}
/**
@@ -271,10 +296,10 @@ class _Xenforo extends \IPS\convert\Software
{
try
{
$title = ( static::$isLegacy === FALSE OR \is_null( static::$isLegacy ) ) ? $xfTwoTitle : $xfOneTitle;
$title = ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) ) ? $xfTwoTitle : $xfOneTitle;
return $this->db->select( 'phrase_text', 'xf_phrase', array( "title=?", $title ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
return NULL;
}
@@ -307,7 +332,7 @@ class _Xenforo extends \IPS\convert\Software
break;
}
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
$info = array(
'id' => $row['node_id'],
@@ -423,7 +448,7 @@ class _Xenforo extends \IPS\convert\Software
);
}
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
}
/* Approval */
@@ -452,7 +477,7 @@ class _Xenforo extends \IPS\convert\Software
$key = explode( '-', $redirect['redirect_key'] );
$moved_to = array( $key[1], $key[2] );
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
}
$info = array(
@@ -500,7 +525,7 @@ class _Xenforo extends \IPS\convert\Software
{
$prefix = $this->getPhrase( "thread_prefix_{$row['prefix_id']}", "thread_prefix.{$row['prefix_id']}" );
if ( !\is_null( $prefix ) )
if ( !is_null( $prefix ) )
{
$libraryClass->convertTag( array(
'tag_meta_app' => 'forums',
@@ -519,7 +544,7 @@ class _Xenforo extends \IPS\convert\Software
if ( $row['tags'] )
{
$tags = static::unpack( $row['tags'] );
if ( \count( $tags ) )
if ( count( $tags ) )
{
foreach( $tags AS $key => $tag )
{
@@ -590,7 +615,7 @@ class _Xenforo extends \IPS\convert\Software
$editName = $this->db->select( 'username', 'xf_user', array( 'user_id=?', $row['last_edit_user_id'] ) )->first();
}
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
$info = array(
'pid' => $row['post_id'],
@@ -611,8 +636,8 @@ class _Xenforo extends \IPS\convert\Software
/* Reputation */
if ( !static::$useJson )
{
$likes = \unserialize( $row['like_users'] );
if ( \is_array( $likes ) AND \count( $likes ) )
$likes = unserialize( $row['like_users'] );
if ( is_array( $likes ) AND count( $likes ) )
{
foreach( $likes AS $like )
{
@@ -714,9 +739,9 @@ class _Xenforo extends \IPS\convert\Software
{
$topic = $this->db->select( 'thread_id', 'xf_post', array( "post_id=?", $row['content_id'] ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
$this->app->log( 'xf_attach_missing_topic_link', __METHOD__, \IPS\convert\App::LOG_WARNING, $row['attachment_id'] );
$this->app->log( 'xf_attach_missing_topic_link', __METHOD__, App::LOG_WARNING, $row['attachment_id'] );
$libraryClass->setLastKeyValue( $row['attachment_id'] );
continue;
}
@@ -752,17 +777,17 @@ class _Xenforo extends \IPS\convert\Software
{
$pid = $this->app->getLink( $row['content_id'], '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( "/\[ATTACH([^\]]+?)?\]" . $row['attachment_id'] . "(\._xfImport)?\[\/ATTACH\]/i", $post ) )
{
$post = preg_replace( "/\[ATTACH([^\]]+?)?\]" . $row['attachment_id'] . "(\._xfImport)?\[\/ATTACH\]/i", '[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['attachment_id'] );
}
@@ -771,13 +796,13 @@ class _Xenforo 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( preg_match( '#/(forums|threads)/(.+?)\.([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
if( preg_match( '#/(forums|threads)/(.+?)\.([0-9]+)#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
{
$oldId = (int) $matches[3];
@@ -794,7 +819,7 @@ class _Xenforo extends \IPS\convert\Software
break;
}
}
elseif( preg_match( '#/posts/([0-9]+)/#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
elseif( preg_match( '#/posts/([0-9]+)/#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
{
$class = '\IPS\forums\Topic\Post';
$types = array( 'posts', 'forums_posts' );
@@ -809,20 +834,20 @@ class _Xenforo 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' ) )
{
@@ -830,7 +855,7 @@ class _Xenforo extends \IPS\convert\Software
}
}
}
catch( \Exception $e )
catch( Exception $e )
{
return NULL;
}