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

@@ -11,16 +11,40 @@
namespace IPS\convert\Software\Core;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use Exception;
use IPS\Application\Module;
use IPS\Content\Search\Index;
use IPS\convert\Software;
use IPS\core\Ignore;
use IPS\Data\Cache;
use IPS\Data\Store;
use IPS\Db;
use IPS\Http\Url;
use IPS\Login;
use IPS\Member;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Request;
use IPS\Task;
use OutOfRangeException;
use PasswordHash;
use UnderflowException;
use function count;
use function defined;
use function file_exists;
use function in_array;
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;
}
/**
* SMF Core Converter
*/
class _Smf extends \IPS\convert\Software
class Smf extends Software
{
/**
* Software Name
@@ -130,13 +154,13 @@ class _Smf extends \IPS\convert\Software
{
return $this->db->select( 'SUM(CHAR_LENGTH(buddy_list) - CHAR_LENGTH(REPLACE(buddy_list, ",", "") + 1))', 'members', array( "pm_ignore_list!=?", '' ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
return 0;
}
catch( \Exception $e )
catch( Exception $e )
{
throw new \IPS\convert\Exception( sprintf( \IPS\Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
throw new \IPS\convert\Exception( sprintf( Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
}
break;
@@ -164,7 +188,7 @@ class _Smf extends \IPS\convert\Software
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => NULL,
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
);
$return['convertEmoticons']['keep_existing_emoticons'] = array(
'field_class' => 'IPS\\Helpers\\Form\\Checkbox',
@@ -179,16 +203,16 @@ class _Smf extends \IPS\convert\Software
$return['convertProfileFields'] = array();
$options = array();
$options['none'] = \IPS\Member::loggedIn()->language()->addToStack( 'none' );
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_pfields_data' ), 'IPS\core\ProfileFields\Field' ) AS $field )
$options['none'] = Member::loggedIn()->language()->addToStack( 'none' );
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'core_pfields_data' ), 'IPS\core\ProfileFields\Field' ) AS $field )
{
$options[$field->_id] = $field->_title;
}
foreach( $this->db->select( '*', 'custom_fields' ) AS $field )
{
\IPS\Member::loggedIn()->language()->words["map_pfield_{$field['id_field']}"] = $field['field_name'];
\IPS\Member::loggedIn()->language()->words["map_pfield_{$field['id_field']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_pfield_desc' );
Member::loggedIn()->language()->words["map_pfield_{$field['id_field']}"] = $field['field_name'];
Member::loggedIn()->language()->words["map_pfield_{$field['id_field']}_desc"] = Member::loggedIn()->language()->addToStack( 'map_pfield_desc' );
$return['convertProfileFields']["map_pfield_{$field['id_field']}"] = array(
'field_class' => 'IPS\\Helpers\\Form\\Select',
@@ -204,16 +228,16 @@ class _Smf extends \IPS\convert\Software
$return['convertGroups'] = array();
$options = array();
$options['none'] = \IPS\Member::loggedIn()->language()->addToStack( 'none' );
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
$options['none'] = Member::loggedIn()->language()->addToStack( 'none' );
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
{
$options[$group->g_id] = $group->name;
}
foreach( $this->db->select( '*', 'membergroups' ) AS $group )
{
\IPS\Member::loggedIn()->language()->words["map_group_{$group['id_group']}"] = $group['group_name'];
\IPS\Member::loggedIn()->language()->words["map_group_{$group['id_group']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_group_desc' );
Member::loggedIn()->language()->words["map_group_{$group['id_group']}"] = $group['group_name'];
Member::loggedIn()->language()->words["map_group_{$group['id_group']}_desc"] = Member::loggedIn()->language()->addToStack( 'map_group_desc' );
$return['convertGroups']["map_group_{$group['id_group']}"] = array(
'field_class' => 'IPS\\Helpers\\Form\\Select',
@@ -236,14 +260,14 @@ class _Smf extends \IPS\convert\Software
'field_hint' => NULL,
);
\IPS\Member::loggedIn()->language()->words['photo_location_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'photo_location_nodb_desc' );
Member::loggedIn()->language()->words['photo_location_desc'] = Member::loggedIn()->language()->addToStack( 'photo_location_nodb_desc' );
$return['convertMembers']['photo_location'] = array(
'field_class' => 'IPS\\Helpers\\Form\\Text',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => "This is typically: /path/to/smf/attachments/",
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
);
$return['convertMembers']['gallery_location'] = array(
@@ -252,21 +276,21 @@ class _Smf extends \IPS\convert\Software
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => "This is typically: /path/to/smf/uploads/avatars/",
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
);
foreach( array( 'gender', 'website_url', 'location', 'icq', 'aim', 'yim', 'msn', 'personal_text', 'usertitle' ) AS $field )
{
\IPS\Member::loggedIn()->language()->words["field_{$field}"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field', FALSE, array( 'sprintf' => $field ) );
\IPS\Member::loggedIn()->language()->words["field_{$field}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field_desc' );
Member::loggedIn()->language()->words["field_{$field}"] = Member::loggedIn()->language()->addToStack( 'pseudo_field', FALSE, array( 'sprintf' => $field ) );
Member::loggedIn()->language()->words["field_{$field}_desc"] = Member::loggedIn()->language()->addToStack( 'pseudo_field_desc' );
$return['convertMembers']["field_{$field}"] = array(
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => 'no_convert',
'field_required' => TRUE,
'field_extra' => array(
'options' => array(
'no_convert' => \IPS\Member::loggedIn()->language()->addToStack( 'no_convert' ),
'create_field' => \IPS\Member::loggedIn()->language()->addToStack( 'create_field' ),
'no_convert' => Member::loggedIn()->language()->addToStack( 'no_convert' ),
'create_field' => Member::loggedIn()->language()->addToStack( 'create_field' ),
),
'userSuppliedInput' => 'create_field'
),
@@ -287,36 +311,38 @@ class _Smf extends \IPS\convert\Software
public function finish()
{
/* Search Index Rebuild */
\IPS\Content\Search\Index::i()->rebuild();
Index::i()->rebuild();
/* Clear Cache and Store */
\IPS\Data\Store::i()->clearAll();
\IPS\Data\Cache::i()->clearAll();
Store::i()->clearAll();
Cache::i()->clearAll();
/* Non-Content Rebuilds */
\IPS\Task::queue( 'convert', 'RebuildProfilePhotos', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
\IPS\Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_members', 'extension' => 'core_Signatures' ), 2, array( 'app', 'link', 'extension' ) );
\IPS\Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_message_posts', 'extension' => 'core_Messaging' ), 2, array( 'app', 'link', 'extension' ) );
Task::queue( 'convert', 'RebuildProfilePhotos', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_members', 'extension' => 'core_Signatures' ), 2, array( 'app', 'link', 'extension' ) );
Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_message_posts', 'extension' => 'core_Messaging' ), 2, array( 'app', 'link', 'extension' ) );
/* Content Counts */
\IPS\Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
/* First Post Data */
\IPS\Task::queue( 'convert', 'RebuildConversationFirstIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
Task::queue( 'convert', 'RebuildConversationFirstIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
/* Attachments */
\IPS\Task::queue( 'core', 'RebuildAttachmentThumbnails', array( 'app' => $this->app->app_id ), 1, array( 'app' ) );
Task::queue( 'core', 'RebuildAttachmentThumbnails', array( 'app' => $this->app->app_id ), 1, array( 'app' ) );
return array( "f_search_index_rebuild", "f_clear_caches", "f_rebuild_pms", "f_signatures_rebuild", "f_rebuild_attachments" );
}
/**
* 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
{
// Replace BBCode - The table HTML is removed by our parser, but it leaves the posts cleaner than having unparsed bbcode
$search = array( '[li]', '[/li]', '[table]', '[/table]', '[tr]', '[/tr]', '[td]', '[/td]', '[tt]', '[/tt]' );
@@ -531,10 +557,10 @@ class _Smf extends \IPS\convert\Software
'pf_type' => $type,
'pf_name' => $row['field_name'],
'pf_desc' => $row['field_desc'],
'pf_content' => ( \in_array( $row['field_type'], array( 'select', 'radio' ) ) ) ? json_encode( explode( ',', $row['field_options'] ) ) : NULL,
'pf_content' => ( in_array( $row['field_type'], array( 'select', 'radio' ) ) ) ? json_encode( explode( ',', $row['field_options'] ) ) : NULL,
'pf_not_null' => ( $row['show_reg'] == 2 ) ? 1 : 0,
'pf_member_hide' => ( $row['private'] >= 3 ) ? 'hide' : 'all',
'pf_max_input' => ( !\in_array( $row['field_type'], array( 'select', 'radio', 'check' ) ) ) ? $row['field_length'] : NULL,
'pf_max_input' => ( !in_array( $row['field_type'], array( 'select', 'radio', 'check' ) ) ) ? $row['field_length'] : NULL,
'pf_member_edit' => ( $row['private'] < 4 ) ? 1 : 0,
'pf_position' => $row['placement'],
'pf_show_on_reg' => ( $row['show_reg'] >= 1 ) ? 1 : 0,
@@ -587,7 +613,7 @@ class _Smf extends \IPS\convert\Software
}
/* Now check for group promotions */
if( \count( $libraryClass->groupPromotions ) )
if( count( $libraryClass->groupPromotions ) )
{
foreach( $libraryClass->groupPromotions as $groupPromotion )
{
@@ -639,7 +665,7 @@ class _Smf extends \IPS\convert\Software
$rp = $time;
}
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
/* Catch out of range issues */
if( $ban > 2147483647 )
@@ -698,7 +724,7 @@ class _Smf extends \IPS\convert\Software
{
$fieldId = $this->app->getLink( $pseudo, 'core_pfields_data' );
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
$type = 'Text';
$content = '[]';
@@ -769,13 +795,13 @@ class _Smf extends \IPS\convert\Software
/* Remote */
try
{
$file = \IPS\Http\Url::external( $row['avatar'] )->request()->get();
$file = Url::external( $row['avatar'] )->request()->get();
$filename = explode( '/', $row['avatar'] );
$filename = array_pop( $filename );
$filedata = (string) $file;
}
catch( \Exception $e ) {}
catch( Exception $e ) {}
}
else
{
@@ -815,18 +841,18 @@ class _Smf extends \IPS\convert\Software
$legacyName = preg_replace( '~\.[\.]+~', '.', $cleanName );
}
if ( \file_exists( $path . '/' . $location ) )
if ( file_exists( $path . '/' . $location ) )
{
$filename = $attach['filename'];
$filepath = $path . '/' . $location;
}
elseif( !empty( $legacyName ) AND \file_exists( $path . '/' . $legacyName ) )
elseif( !empty( $legacyName ) AND file_exists( $path . '/' . $legacyName ) )
{
$filename = $attach['filename'];
$filepath = $path;
}
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
}
$libraryClass->convertMember( $info, $pfields, $filename, $filepath, $filedata );
@@ -860,7 +886,7 @@ class _Smf extends \IPS\convert\Software
$info['ignore_owner_id'] = $row['id_member'];
$info['ignore_ignore_id'] = $id;
foreach( \IPS\core\Ignore::types() AS $type )
foreach( Ignore::types() AS $type )
{
$info['ignore_' . $type] = 1;
}
@@ -874,26 +900,26 @@ class _Smf 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
* @note Current profile URL format: /index.php?action=profile;u=123
*/
public function checkRedirects()
{
/* If we can't access profiles, don't bother trying to redirect */
if( !\IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members' ) ) )
if( !Member::loggedIn()->canAccessModule( Module::get( 'core', 'members' ) ) )
{
return NULL;
}
if( isset( \IPS\Request::i()->action ) AND mb_strpos( \IPS\Request::i()->action, 'profile' ) !== FALSE )
if( isset( Request::i()->action ) AND mb_strpos( Request::i()->action, 'profile' ) !== FALSE )
{
if( isset( \IPS\Request::i()->u ) )
if( isset( Request::i()->u ) )
{
$oldId = \IPS\Request::i()->u;
$oldId = Request::i()->u;
}
else
{
$pieces = explode( ';', \IPS\Request::i()->action );
$pieces = explode( ';', Request::i()->action );
foreach( $pieces as $piece )
{
@@ -910,9 +936,9 @@ class _Smf extends \IPS\convert\Software
try
{
$data = (string) $this->app->getLink( $oldId, array( 'members', 'core_members' ) );
return \IPS\Member::load( $data )->url();
return Member::load( $data )->url();
}
catch( \Exception $e )
catch( Exception $e )
{
return NULL;
}
@@ -924,29 +950,29 @@ class _Smf extends \IPS\convert\Software
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param Member $member The member
* @param string $password Password from form
* @return bool
*/
public static function login( $member, $password )
{
if ( \IPS\Login::compareHashes( $member->conv_password, sha1( mb_strtolower( $member->name ) . html_entity_decode( $password ) ) ) )
if ( Login::compareHashes( $member->conv_password, sha1( mb_strtolower( $member->name ) . html_entity_decode( $password ) ) ) )
{
return TRUE;
}
else if ( \IPS\Login::compareHashes( $member->conv_password, sha1( mb_strtolower( $member->name ) . $password ) ) )
else if ( Login::compareHashes( $member->conv_password, sha1( mb_strtolower( $member->name ) . $password ) ) )
{
return TRUE;
}
/* In 4.2.6 we save the original members name as the salt so that we don't have one that has been modified in the conversion process */
else if ( \IPS\Login::compareHashes( $member->conv_password, sha1( mb_strtolower( $member->conv_password_extra ) . $password ) ) )
else if ( Login::compareHashes( $member->conv_password, sha1( mb_strtolower( $member->conv_password_extra ) . $password ) ) )
{
return TRUE;
}
else
{
require_once \IPS\ROOT_PATH . "/applications/convert/sources/Login/PasswordHash.php";
$ph = new \PasswordHash( 8, TRUE );
$ph = new PasswordHash( 8, TRUE );
if( $ph->CheckPassword( mb_strtolower( $member->name ) . $password, $member->conv_password ) )
{