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,19 +5,22 @@
* @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;
}
/**
* vBulletin 5 Forums Converter
*/
class _Vbulletin5 extends \IPS\convert\Software
{
/**
@@ -63,12 +66,38 @@ class _Vbulletin5 extends \IPS\convert\Software
'where' => NULL,
),
'convertAttachments' => array(
'table' => 'attachment',
'where' => NULL,
'extra_steps' => array( 'convertAttachments2' )
),
'convertAttachments2' => array(
'table' => 'attachment',
'where' => NULL
)
),
);
}
/**
* Allows software to add additional menu row options
*
* @return array
*/
public function extraMenuRows()
{
$rows = array();
$rows['convertAttachments2'] = array(
'step_method' => 'convertAttachments2',
'step_title' => 'convert_attachments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments_map', array( "location_key=?", 'gallery_Images' ) ),
'source_rows' => array( 'table' => static::canConvert()['convertAttachments2']['table'], 'where' => static::canConvert()['convertAttachments2']['where'] ),
'per_cycle' => 10,
'dependencies' => array( 'convertAttachments' ),
'link_type' => 'core_attachments',
);
return $rows;
}
/**
* Count Source Rows for a specific step
*
@@ -83,19 +112,33 @@ class _Vbulletin5 extends \IPS\convert\Software
switch( $table )
{
case 'forum':
return count( $this->fetchForums() );
return \count( $this->fetchForums() );
break;
case 'thread':
return parent::countRows( 'node', array( \IPS\Db::i()->in( 'contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Poll' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ) ) ) . " AND " . \IPS\Db::i()->in( 'parentid', array_keys( $this->fetchForums() ) ), $this->fetchType( 'Text' ), $this->fetchType( 'Poll' ) ) );
try
{
return parent::countRows( 'node', array( \IPS\Db::i()->in( 'contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Poll' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ) ) ) . " AND " . \IPS\Db::i()->in( 'parentid', array_keys( $this->fetchForums() ) ), $this->fetchType( 'Text' ), $this->fetchType( 'Poll' ) ) );
}
catch( \Exception $e )
{
throw new \IPS\convert\Exception( sprintf( \IPS\Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
}
break;
case 'post':
return parent::countRows( 'node', array( \IPS\Db::i()->in( 'contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ), $this->fetchType( 'Poll' ) ) ) ) );
try
{
return parent::countRows( 'node', array( \IPS\Db::i()->in( 'contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ), $this->fetchType( 'Poll' ) ) ) ) );
}
catch( \Exception $e )
{
throw new \IPS\convert\Exception( sprintf( \IPS\Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
}
break;
case 'attachment':
return parent::countRows( 'node', array( "contenttypeid=?", $this->fetchType( 'Attach' ) ) );
return parent::countRows( 'node', array( "contenttypeid IN (" . $this->fetchType( 'Attach' ) . ',' . $this->fetchType( 'Photo' ) . ")" ) );
break;
default:
@@ -132,10 +175,10 @@ class _Vbulletin5 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( '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' ) );
/* Rebuild Leaderboard */
\IPS\Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
@@ -147,7 +190,7 @@ class _Vbulletin5 extends \IPS\convert\Software
/**
* Fix Post Data
*
* @param string Post
* @param string $post Post
* @return string Fixed Posts
*/
public static function fixPostData( $post )
@@ -194,7 +237,7 @@ class _Vbulletin5 extends \IPS\convert\Software
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array( 'parse' => 'image', 'options' => $options, 'descriptions' => $descriptions ),
'field_extra' => array( 'parse' => 'image', 'options' => $options, 'descriptions' => $descriptions, 'gridspan' => 2 ),
'field_hint' => NULL,
'field_validation' => NULL,
),
@@ -209,8 +252,8 @@ class _Vbulletin5 extends \IPS\convert\Software
'field_required' => TRUE,
'field_extra' => array(
'options' => array(
'database' => \IPS\Member::loggedIn()->language()->addToStack( 'database' ),
'file_system' => \IPS\Member::loggedIn()->language()->addToStack( 'file_system' ),
'database' => \IPS\Member::loggedIn()->language()->addToStack( 'conv_store_database' ),
'file_system' => \IPS\Member::loggedIn()->language()->addToStack( 'conv_store_file_system' ),
),
'userSuppliedInput' => 'file_system',
),
@@ -301,7 +344,7 @@ class _Vbulletin5 extends \IPS\convert\Software
$libraryClass::setKey( 'node.nodeid' );
$clubs = $this->fetchClubs();
foreach( $this->fetch( 'node', 'node.nodeid', array( "( " . \IPS\Db::i()->in( 'node.parentid', array_keys( $this->fetchForums() ) ) . " OR " . $this->db->in( 'node.parentid', array_keys( $clubs ) ) . " ) AND " . \IPS\Db::i()->in( 'node.contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Poll' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ) ) ) ) )->join( 'text', 'text.nodeid = node.nodeid' ) AS $topic )
foreach( $this->fetch( 'node', 'node.nodeid', array( "( " . \IPS\Db::i()->in( 'node.parentid', array_keys( $this->fetchForums() ) ) . " OR " . $this->db->in( 'node.parentid', array_keys( $clubs ) ) . " ) AND " . \IPS\Db::i()->in( 'node.contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Poll' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ) ) ) ) ) AS $topic )
{
/* Pesky Polls */
$poll = NULL;
@@ -414,8 +457,8 @@ class _Vbulletin5 extends \IPS\convert\Software
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'node.nodeid' );
foreach( $this->fetch( 'node', 'node.nodeid', array( \IPS\Db::i()->in( 'node.contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ), $this->fetchType( 'Poll' ) ) ) ) )->join( 'text', 'text.nodeid = node.nodeid' ) AS $post )
foreach( $this->fetch( 'node', 'node.nodeid', array( \IPS\Db::i()->in( 'node.contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ), $this->fetchType( 'Poll' ) ) ) ), 'node.*, text.rawtext, text.htmlstate' )->join( 'text', 'text.nodeid = node.nodeid' ) AS $post )
{
/* Comments of comments of comments of comments */
$isSubComment = FALSE;
@@ -488,21 +531,56 @@ class _Vbulletin5 extends \IPS\convert\Software
'ip_address' => $post['ipaddress'],
'post_date' => $post['publishdate'],
'queued' => $queued,
'post_htmlstate' => ( in_array( $post['htmlstate'], array( 'on', 'on_nl2br' ) ) ) ? 1 : 0,
'post_htmlstate' => ( \in_array( $post['htmlstate'], array( 'on', 'on_nl2br' ) ) ) ? 1 : 0,
);
/* Any vB5 Links? */
if( $post['contenttypeid'] == $this->fetchType( 'Link' ) )
{
try
{
$link = $this->db->select( 'url, url_title', 'link', array('nodeid=?', $post['nodeid']) )->first();
if ( !empty( $link['url_title'] ) )
{
$info['post'] .= <<<LINK
[url={$link['url']}]{$link['url_title']}[/url]
LINK;
}
else
{
$info['post'] .= <<<LINK
[url]{$link['url']}[/url]
LINK;
}
}
catch ( \UnderflowException $e ) {}
}
$post_id = $libraryClass->convertForumsPost( $info );
/* Need to insert into the SDL? */
if ( $softDeleted )
{
try
{
$softDeleteId = $this->app->getLink( $post['deleteuserid'], 'core_members', TRUE );
}
/* User link doesn't exist */
catch( \OutOfRangeException $e )
{
$softDeleteId = 0;
}
\IPS\Db::i()->insert( 'core_soft_delete_log', array(
'sdl_obj_id' => $post_id,
'sdl_obj_key' => 'post',
'sdl_obj_member_id' => $this->app->getLink( $post['deleteuserid'], 'core_members', TRUE ),
'sdl_obj_date' => $post['unpublishdate'] ?: time(),
'sdl_obj_reason' => $post['deletereason'] ?: NULL,
'sdl_locked' => 0
'sdl_obj_id' => $post_id,
'sdl_obj_key' => 'post',
'sdl_obj_member_id' => $softDeleteId,
'sdl_obj_date' => $post['unpublishdate'] ?: time(),
'sdl_obj_reason' => $post['deletereason'] ?: NULL,
'sdl_locked' => 0
) );
}
@@ -693,9 +771,9 @@ class _Vbulletin5 extends \IPS\convert\Software
continue;
}
if ( preg_match( "/\[ATTACH=(.+?)?\]n" . $attachment['nodeid'] . "\[\/ATTACH\]/i", $post ) )
if ( preg_match( "/\[ATTACH([^\]]+?)?\]n" . $attachment['nodeid'] . "\[\/ATTACH\]/i", $post ) )
{
$post = preg_replace( "/\[ATTACH(.+?)?\]" . $attachment['nodeid'] . "\[\/ATTACH\]/i", '[attachment=' . $attach_id . ':name]', $post );
$post = preg_replace( "/\[ATTACH([^\]]+?)?\]n" . $attachment['nodeid'] . "\[\/ATTACH\]/i", '[attachment=' . $attach_id . ':name]', $post );
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
}
@@ -712,10 +790,10 @@ class _Vbulletin5 extends \IPS\convert\Software
/* Don't fail if this table/value doesn't exist */
catch( \Exception $e ) { }
if ( $oldAttachId !== NULL and preg_match( "/\[ATTACH=(.+?)?\]" . $oldAttachId . "\[\/ATTACH\]/i", $post ) )
if ( $oldAttachId !== NULL and preg_match( "/\[ATTACH([^\]]+?)?\]" . $oldAttachId . "\[\/ATTACH\]/i", $post ) )
{
$update = TRUE;
$post = preg_replace( "/\[ATTACH(.+?)?\]" . $oldAttachId . "\[\/ATTACH\]/i", '[attachment=' . $attach_id . ':name]', $post );
$post = preg_replace( "/\[ATTACH([^\]]+?)?\]" . $oldAttachId . "\[\/ATTACH\]/i", '[attachment=' . $attach_id . ':name]', $post );
}
elseif( preg_match( "/\[ATTACH=JSON](.+?)\"data-attachmentid\":\"?{$attachment['nodeid']}\"?(.+?)\[\/ATTACH\]/i", $post ) )
{
@@ -733,6 +811,103 @@ class _Vbulletin5 extends \IPS\convert\Software
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
}
}
/**
* Convert attachments (photo posts)
*
* @return void
*/
public function convertAttachments2()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'node.nodeid' );
$main = $this->fetch( 'node', 'node.nodeid', array( "node.contenttypeid=?", $this->fetchType( 'Photo' ) ) )
->join( 'photo', 'photo.nodeid = node.nodeid' )
->join( 'filedata', 'filedata.filedataid = photo.filedataid' );
foreach( $main AS $attachment )
{
/* This is the first post in the topic */
try
{
$this->app->getLink( $attachment['parentid'], 'forums_topics' );
$post_id = $attachment['parentid'];
}
/* It isn't the first post in the topic */
catch( \OutOfRangeException $e )
{
try
{
$this->app->getLink( $attachment['parentid'], 'forums_posts' );
$parent = $this->db->select( 'nodeid, parentid', 'node', array( "nodeid=?", $attachment['parentid'] ) )->first();
$attachment['parentid'] = $parent['parentid'];
$post_id = $parent['nodeid'];
}
catch( \OutOfRangeException $e )
{
/* No valid converter link for the parent post */
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
$this->app->log( 'vb5_attach_missing_post_link', __METHOD__, \IPS\convert\App::LOG_WARNING, $attachment['nodeid'] );
continue;
}
catch( \UnderflowException $e )
{
/* Parent post does not exist in vB database */
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
$this->app->log( 'vb5_attach_missing_post', __METHOD__, \IPS\convert\App::LOG_WARNING, $attachment['nodeid'] );
continue;
}
}
$map = array(
'id1' => $attachment['parentid'],
'id2' => $post_id
);
$info = array(
'attach_id' => $attachment['nodeid'],
'attach_file' => $attachment['filehash'] . '.' . $attachment['extension'],
'attach_date' => $attachment['dateline'],
'attach_member_id' => $attachment['userid'],
'attach_hits' => 0,
'attach_ext' => $attachment['extension'],
'attach_filesize' => $attachment['filesize'],
);
if ( $this->app->_session['more_info']['convertAttachments']['file_location'] == 'database' )
{
/* Simples! */
$data = $attachment['filedata'];
$path = NULL;
}
else
{
$data = NULL;
$path = implode( '/', preg_split( '//', $attachment['userid'], -1, PREG_SPLIT_NO_EMPTY ) );
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['file_location'], '/' ) . '/' . $path . '/' . $attachment['filedataid'] . '.attach';
/* Apparently vBulletin had a bug between 5.0.0 and 5.1.3 where attachments were incorrectly stored in /path/userid/file.attach rather than in the user ID split location */
if ( !file_exists( $path ) )
{
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['file_location'], '/' ) . '/' . $attachment['userid'] . '/' . $attachment['filedataid'] . '.attach';
}
/* Still not there? It might be in the database still */
if ( !file_exists( $path ) AND $attachment['filedata'] )
{
$data = $attachment['filedata'];
$path = NULL;
}
}
$attach_id = $libraryClass->convertAttachment( $info, $map, $path, $data );
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
}
}
/* !vBulletin Stuff */
@@ -769,7 +944,7 @@ class _Vbulletin5 extends \IPS\convert\Software
/**
* Helper method to retrieve forums from nodes
*
* @return void
* @return array
*/
protected function fetchForums()
{
@@ -822,11 +997,12 @@ class _Vbulletin5 extends \IPS\convert\Software
/**
* Helper method to retrieve content type ids
*
* @param int|string $type The content type
* @return void
*/
protected function fetchType( $type )
{
if ( count( $this->typesCache ) )
if ( \count( $this->typesCache ) )
{
return $this->typesCache[ $type ];
}