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

@@ -14,11 +14,11 @@ namespace IPS\convert\Software\Blog;
/* To prevent PHP errors (extending class does not exist) revealing path */
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;
}
class _Invisioncommunity extends \IPS\convert\Software
class Invisioncommunity extends \IPS\convert\Software
{
/**
* @brief Whether the versions of IPS4 match
@@ -12,16 +12,35 @@
namespace IPS\convert\Software\Blog;
/* 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\blog\Entry;
use IPS\convert\App;
use IPS\convert\Software;
use IPS\convert\Software\Core\Vbulletin as VbulletinClass;
use IPS\Db;
use IPS\Http\Url;
use IPS\Member;
use IPS\Request;
use IPS\Task;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
use function is_null;
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;
}
/**
* vBulletin Blog Converter
*/
class _Vbulletin extends \IPS\convert\Software
class Vbulletin extends Software
{
/**
* @brief vBulletin 4 Stores all attachments under one table - this will store the content type for the blog app.
@@ -36,12 +55,12 @@ class _Vbulletin 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 );
@@ -64,12 +83,12 @@ class _Vbulletin extends \IPS\convert\Software
/* If this is vB4, what is the content type ID for posts? */
if ( static::$entryContentType === NULL AND ( static::$isLegacy === FALSE OR \is_null( static::$isLegacy ) ) AND $needDB )
if ( static::$entryContentType === NULL AND ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) ) AND $needDB )
{
static::$entryContentType = $this->db->select( 'contenttypeid', 'contenttype', array( "class=?", 'BlogEntry' ) )->first();
}
}
catch( \Exception $e ) {}
catch( Exception $e ) {}
return $return;
}
@@ -105,7 +124,7 @@ class _Vbulletin extends \IPS\convert\Software
{
$attachmentTable = 'blog_attachment';
$attachmentWhere = NULL;
if ( static::$isLegacy === FALSE OR \is_null( static::$isLegacy ) )
if ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) )
{
$attachmentTable = 'attachment';
$attachmentWhere = array( "contenttypeid=?", static::$entryContentType );
@@ -186,23 +205,25 @@ class _Vbulletin extends \IPS\convert\Software
public function finish()
{
/* Content Rebuilds */
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\blog\Entry\Category', 'count' => 0 ), 4, array( 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'blog_entries', 'class' => 'IPS\blog\Entry' ), 2, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'blog_comments', 'class' => 'IPS\blog\Entry\Comment' ), 2, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'blog_entries', 'class' => 'IPS\blog\Entry' ), 3, array( 'app', 'link', 'class' ) );
Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\blog\Entry\Category', 'count' => 0 ), 4, array( 'class' ) );
Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'blog_entries', 'class' => 'IPS\blog\Entry' ), 2, array( 'app', 'link', 'class' ) );
Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'blog_comments', 'class' => 'IPS\blog\Entry\Comment' ), 2, array( 'app', 'link', 'class' ) );
Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'blog_entries', 'class' => 'IPS\blog\Entry' ), 3, array( 'app', 'link', 'class' ) );
return array( "f_blog_entries_rebuilding", "f_entry_comments_rebuilding", "f_blogs_recounting", "f_entry_tags_cache" );
}
/**
* Fix Post Data
* Pre-process content for the Invision Community text parser
*
* @param string $post Post
* @return string Fixed Posts
* @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\Vbulletin::fixPostData( $post );
return CalendarClass::fixPostData( $post, $className, $contentId );
}
/**
@@ -234,13 +255,13 @@ class _Vbulletin extends \IPS\convert\Software
'field_required' => TRUE,
'field_extra' => array(
'options' => array(
'database' => \IPS\Member::loggedIn()->language()->addToStack( 'conv_store_database' ),
'file_system' => \IPS\Member::loggedIn()->language()->addToStack( 'conv_store_file_system' ),
'database' => Member::loggedIn()->language()->addToStack( 'conv_store_database' ),
'file_system' => Member::loggedIn()->language()->addToStack( 'conv_store_file_system' ),
),
'userSuppliedInput' => 'file_system',
),
'field_hint' => NULL,
'field_validation' => function( $value ) { if ( $value != 'database' AND !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
'field_validation' => function( $value ) { if ( $value != 'database' AND !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
)
);
break;
@@ -266,7 +287,7 @@ class _Vbulletin extends \IPS\convert\Software
{
$member = $this->db->select( '*', 'user', array( "userid=?", $blog['bloguserid'] ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
/* User no longer exists, so skip */
$libraryClass->setLastKeyValue( $blog['bloguserid'] );
@@ -376,7 +397,7 @@ class _Vbulletin extends \IPS\convert\Software
{
$text = $this->db->select( '*', 'blog_text', array( "blogtextid=?", $entry['firstblogtextid'] ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
$libraryClass->setLastKeyValue( $entry['blogid'] );
continue;
@@ -388,7 +409,7 @@ class _Vbulletin extends \IPS\convert\Software
{
$lastcommenterid = $this->db->select( 'userid', 'blog_text', array( "blogtextid=?", $entry['lastblogtextid'] ) )->first();
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
$status = 'published';
if ( $entry['state'] == 'draft' )
@@ -404,7 +425,7 @@ class _Vbulletin extends \IPS\convert\Software
$editname = $editlog['username'];
$editReason = $editlog['reason'];
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
$categories = explode( ',', $entry['categories'] );
$mainCategory = array_pop( $categories );
@@ -446,7 +467,7 @@ class _Vbulletin extends \IPS\convert\Software
) );
}
if ( \count( $categories ) )
if ( count( $categories ) )
{
foreach( $categories as $category )
{
@@ -454,7 +475,7 @@ class _Vbulletin extends \IPS\convert\Software
{
$data = $this->db->select( '*', 'blog_category', array( "blogcategoryid=?", $category ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
continue;
}
@@ -521,7 +542,7 @@ class _Vbulletin extends \IPS\convert\Software
$edittime = $editlog['dateline'];
$editname = $editlog['username'];
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
switch( $comment['state'] )
{
@@ -571,7 +592,7 @@ class _Vbulletin extends \IPS\convert\Software
$where = NULL;
$column = NULL;
if ( static::$isLegacy === FALSE OR \is_null( static::$isLegacy ) )
if ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) )
{
$where = array( "contenttypeid=?", static::$entryContentType );
$column = 'contentid';
@@ -585,17 +606,17 @@ class _Vbulletin extends \IPS\convert\Software
foreach( $this->fetch( $table, 'attachmentid', $where ) as $attachment )
{
if ( static::$isLegacy === FALSE OR \is_null( static::$isLegacy ) )
if ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) )
{
try
{
$filedata = $this->db->select( '*', 'filedata', array( "filedataid=?", $attachment['filedataid'] ) )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
/* If the filedata row is missing, there isn't much we can do. */
$libraryClass->setLastKeyValue( $attachment['attachmentid'] );
$this->app->log( 'vb_attach_missing_filedata', __METHOD__, \IPS\convert\App::LOG_WARNING, $attachment['attachmentid'] );
$this->app->log( 'vb_attach_missing_filedata', __METHOD__, App::LOG_WARNING, $attachment['attachmentid'] );
continue;
}
}
@@ -650,16 +671,16 @@ class _Vbulletin extends \IPS\convert\Software
/* Do some re-jiggery on the post itself to make sure attachment displays */
$entry_id = $this->app->getLink( $attachment[ $column ], 'blog_entries' );
$post = \IPS\Db::i()->select( 'entry_content', 'blog_entries', array( "entry_id=?", $entry_id ) )->first();
$post = Db::i()->select( 'entry_content', 'blog_entries', array( "entry_id=?", $entry_id ) )->first();
if ( preg_match( "/\[ATTACH([^\]]+?)?\]".$attachment['attachmentid']."\[\/ATTACH\]/i", $post ) )
{
$post = preg_replace( "/\[ATTACH([^\]]+?)?\]" . $attachment['attachmentid'] . "\[\/ATTACH\]/i", '[attachment=' . $attach_id . ':name]', $post );
\IPS\Db::i()->update( 'blog_entries', array( 'entry_content' => $post ), array( "entry_id=?", $entry_id ) );
Db::i()->update( 'blog_entries', array( 'entry_content' => $post ), array( "entry_id=?", $entry_id ) );
}
}
catch( \UnderflowException $e ) {}
catch( \OutOfRangeException $e ) {}
catch( UnderflowException $e ) {}
catch( OutOfRangeException $e ) {}
}
$libraryClass->setLastKeyValue( $attachment['attachmentid'] );
@@ -669,25 +690,25 @@ class _Vbulletin 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( '#/entries/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
if( preg_match( '#/entries/([0-9]+)#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
{
try
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'blog_entries' ) );
$item = \IPS\blog\Entry::load( $data );
$item = Entry::load( $data );
if( $item->can( 'view' ) )
{
return $item->url();
}
}
catch( \Exception $e ) {}
catch( Exception $e ) {}
}
return NULL;