Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -5,21 +5,26 @@
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\Software\Forums;
/* 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;
}
/**
* Xenforo Forums Converter
*/
class _Xenforo extends \IPS\convert\Software
{
use \IPS\convert\Tools\Xenforo;
/**
* @brief The similarities between XF1 and XF2 are close enough that we can use the same converter
*/
@@ -30,11 +35,16 @@ class _Xenforo extends \IPS\convert\Software
*/
public static $contentFixed = TRUE;
/**
* @brief XF2.1 changed serialized data to json decoded
*/
public static $useJson = FALSE;
/**
* Constructor
*
* @param \IPS\convert\App The application to reference for database and other information.
* @param bool Establish a DB connection
* @param \IPS\convert\App $app The application to reference for database and other information.
* @param bool $needDB Establish a DB connection
* @return void
* @throws \InvalidArgumentException
*/
@@ -49,16 +59,24 @@ 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( "addon_id=?", 'XF' ) )->first();
$version = $this->db->select( 'MAX(version_id)', 'xf_template', array( \IPS\Db::i()->in( 'addon_id', array( 'XF', 'XenForo' ) ) ) )->first();
if ( $version < 2000010 )
{
/* XF1 */
static::$isLegacy = TRUE;
}
else
{
/* XF2 */
static::$isLegacy = FALSE;
}
/* Is this XF 2.1 */
if ( $version > 2010010 )
{
static::$useJson = TRUE;
}
}
}
catch( \Exception $e ) {} # If we can't query, we won't be able to do anything anyway
@@ -75,7 +93,7 @@ class _Xenforo extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "XenForo (1.5.x/2.0.x)";
return "XenForo (1.5.x/2.0.x/2.1.x)";
}
/**
@@ -143,10 +161,16 @@ class _Xenforo extends \IPS\convert\Software
*/
public static function checkConf()
{
return array(
'convertAttachments',
'convertForumsPosts'
$return = array(
'convertAttachments'
);
if( !static::$useJson )
{
$return[] = 'convertForumsPosts';
}
return $return;
}
/**
@@ -161,25 +185,31 @@ class _Xenforo extends \IPS\convert\Software
switch( $method )
{
case 'convertForumsPosts':
/* 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 )
/* XF 1 & 2 */
if( !static::$useJson )
{
$options[ $reaction->id ] = $reaction->_icon->url;
$descriptions[ $reaction->id ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id ) . '<br>' . $reaction->_description;
/* 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 )
{
$options[ $reaction->id ] = $reaction->_icon->url;
$descriptions[ $reaction->id ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id );
}
$return['convertForumsPosts'] = array(
'rep_like' => array(
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array( 'parse' => 'image', 'options' => $options, 'descriptions' => $descriptions, 'gridspan' => 2 ),
'field_hint' => NULL,
'field_validation' => NULL,
),
);
}
$return['convertForumsPosts'] = array(
'rep_like' => array(
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array( 'parse' => 'image', 'options' => $options, 'descriptions' => $descriptions ),
'field_hint' => NULL,
'field_validation' => NULL,
),
);
break;
case 'convertAttachments':
@@ -207,11 +237,11 @@ class _Xenforo extends \IPS\convert\Software
public function finish()
{
/* Content Rebuilds */
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\forums\Forum', 'count' => 0 ), 5, array( 'class' ) );
\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 ), 4, array( 'app' ) );
\IPS\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' ) );
@@ -222,8 +252,8 @@ class _Xenforo extends \IPS\convert\Software
/**
* Fix post data
*
* @param string raw post data
* @return string parsed post data
* @param string $post Raw post data
* @return string Parsed post data
*/
public static function fixPostData( $post )
{
@@ -241,7 +271,7 @@ 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 )
@@ -332,10 +362,11 @@ class _Xenforo extends \IPS\convert\Software
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'thread_id' );
foreach( $this->fetch( 'xf_thread', 'thread_id' ) AS $row )
$data = iterator_to_array( $this->fetch( 'xf_thread', 'thread_id' ) );
$this->app->preCacheLinks( $data, [ 'forums_forums' => 'node_id', 'core_members' => [ 'user_id', 'last_post_user_id' ] ] );
foreach( $data AS $row )
{
/* Poll */
$poll = NULL;
@@ -463,13 +494,13 @@ class _Xenforo extends \IPS\convert\Software
'follow_visible' => 1,
) );
}
/* Tag Prefix */
if ( $row['prefix_id'] )
{
$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',
@@ -486,8 +517,8 @@ class _Xenforo extends \IPS\convert\Software
/* Other tags */
if ( $row['tags'] )
{
$tags = \unserialize( $row['tags'] );
if ( count( $tags ) )
$tags = static::unpack( $row['tags'] );
if ( \count( $tags ) )
{
foreach( $tags AS $key => $tag )
{
@@ -518,30 +549,17 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'post_id' );
foreach( $this->fetch( 'xf_post', 'post_id' ) AS $row )
$posts = iterator_to_array( $this->fetch( 'xf_post', 'post_id', null, 'xf_post.*, xf_ip.ip, xf_thread.discussion_state' )
->join( 'xf_ip', 'xf_post.ip_id=xf_ip.ip_id' )
->join( 'xf_thread', 'xf_post.thread_id=xf_thread.thread_id' ) );
$this->app->preCacheLinks( $posts, [ 'forums_topics' => 'thread_id', 'core_members' => 'user_id' ] );
foreach( $posts AS $row )
{
/* Query for the IP */
try
{
$ip = $this->db->select( 'ip', 'xf_ip', array( "ip_id=?", $row['ip_id'] ) )->first();
}
catch( \UnderflowException $e )
{
$ip = '127.0.0.1';
}
/* Figure out queued stuff */
try
if ( $row['discussion_state'] == 'deleted' )
{
$topic_state = $this->db->select( 'discussion_state', 'xf_thread', array( "thread_id=?", $row['thread_id'] ) )->first();
if ( $topic_state == 'deleted' )
{
$row['message_state'] = 'topic_hidden';
}
$row['message_state'] = 'topic_hidden';
}
catch( \UnderflowException $e ) {}
switch( $row['message_state'] )
{
@@ -578,29 +596,51 @@ class _Xenforo extends \IPS\convert\Software
'post' => static::fixPostData( $row['message'] ),
'edit_time' => $row['last_edit_date'],
'edit_name' => $editName,
'append_edit' => $editName ? 1 : NULL,
'author_id' => $row['user_id'],
'author_name' => $row['username'],
'ip_address' => $ip,
'ip_address' => $row['ip'] ?? '127.0.0.1',
'post_date' => $row['post_date'],
'queued' => $queued,
);
$post_id = $libraryClass->convertForumsPost( $info );
$libraryClass->convertForumsPost( $info );
/* Reputation */
$likes = \unserialize( $row['like_users'] );
if ( count( $likes ) )
if ( !static::$useJson )
{
foreach( $likes AS $like )
$likes = \unserialize( $row['like_users'] );
if ( \is_array( $likes ) AND \count( $likes ) )
{
foreach( $likes AS $like )
{
$libraryClass->convertReputation( array(
'app' => 'forums',
'type' => 'pid',
'type_id' => $row['post_id'],
'member_id' => $like['user_id'],
'member_received' => $row['user_id'],
'reaction' => $this->app->_session['more_info']['convertForumsPosts']['rep_like'],
'rep_date' => $row['post_date']
) );
}
}
}
else
{
$reputation = iterator_to_array( $this->db->select( '*', 'xf_reaction_content', array( "content_type=? AND content_id=?", 'post', $row['post_id'] ) ) );
$this->app->preCacheLinks( $reputation, [ 'core_members' => 'reaction_user_id' ] );
foreach( $reputation as $reaction )
{
$libraryClass->convertReputation( array(
'id' => $reaction['reaction_content_id'],
'app' => 'forums',
'type' => 'pid',
'type_id' => $row['post_id'],
'member_id' => $like['user_id'],
'member_id' => $reaction['reaction_user_id'],
'member_received' => $row['user_id'],
'reaction' => $this->app->_session['more_info']['convertForumsPosts']['rep_like'],
'rep_date' => $row['post_date']
'reaction' => $reaction['reaction_id'],
'rep_date' => $reaction['reaction_date']
) );
}
}
@@ -631,14 +671,13 @@ class _Xenforo extends \IPS\convert\Software
}
/* Edit History */
$latestedit = 0;
$reason = NULL;
$name = NULL;
$newText = static::fixPostData( $row['message'] );
$newText = $info['post'];
foreach( $this->db->select( '*', 'xf_edit_history', array( "content_type=? AND content_id=?", 'post', $row['post_id'] ) ) AS $edit )
{
$libraryClass->convertEditHistory( array(
$editHistory = array(
'id' => $edit['edit_history_id'],
'class' => 'IPS\\forums\\Topic\\Post',
'comment_id' => $row['post_id'],
@@ -646,20 +685,9 @@ class _Xenforo extends \IPS\convert\Software
'time' => $edit['edit_date'],
'old' => static::fixPostData( $edit['old_text'] ),
'new' => $newText
) );
$newText = static::fixPostData( $edit['old_text'] );
if ( $edit['edit_date'] > $latestedit )
{
$latestedit = $edit['edit_date'];
}
}
/* If we have a latest edit, then update the main post - this should really be in the library, as the converters should not be altering data */
if ( $latestedit )
{
\IPS\Db::i()->update( 'forums_posts', array( 'append_edit' => 1, 'edit_time' => $latestedit ), array( "pid=?", $post_id ) );
);
$libraryClass->convertEditHistory( $editHistory );
$newText = $editHistory['old'];
}
$libraryClass->setLastKeyValue( $row['post_id'] );
@@ -716,9 +744,9 @@ class _Xenforo extends \IPS\convert\Software
$post = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
if ( preg_match( "/\[ATTACH(.+?)?\]" . $row['attachment_id'] . "\[\/ATTACH\]/i", $post ) )
if ( preg_match( "/\[ATTACH([^\]]+?)?\]" . $row['attachment_id'] . "\[\/ATTACH\]/i", $post ) )
{
$post = preg_replace( "/\[ATTACH(.+?)?\]" . $row['attachment_id'] . "\[\/ATTACH\]/i", '[attachment=' . $attachId . ':name]', $post );
$post = preg_replace( "/\[ATTACH([^\]]+?)?\]" . $row['attachment_id'] . "\[\/ATTACH\]/i", '[attachment=' . $attachId . ':name]', $post );
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
}
}