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,18 +12,39 @@
namespace IPS\convert\Software\Downloads;
/* 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\Tools\Xenforo;
use IPS\Db;
use IPS\Http\Url;
use IPS\Member;
use IPS\Node\Model;
use IPS\Request;
use IPS\Task;
use OutOfRangeException;
use UnderflowException;
use function defined;
use function in_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 Downloads Converter
*/
class _Xenforo extends \IPS\convert\Software
class Xenforo extends Software
{
use \IPS\convert\Tools\Xenforo;
use Xenforo;
/**
* @brief The similarities between XF1 and XF2 are close enough that we can use the same converter
@@ -43,12 +64,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 +80,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 )
{
@@ -78,7 +99,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;
@@ -205,10 +226,10 @@ class _Xenforo extends \IPS\convert\Software
*/
public function finish()
{
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\downloads\File', 'count' => 0 ), 4, array( 'class' ) );
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\downloads\Category', 'count' => 0 ), 5, array( 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'class' => 'IPS\downloads\File', 'link' => 'downloads_files' ), 2, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'class' => 'IPS\downloads\File\Review', 'link' => 'downloads_reviews' ), 2, array( 'app', 'link', 'class' ) );
Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\downloads\File', 'count' => 0 ), 4, array( 'class' ) );
Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\downloads\Category', 'count' => 0 ), 5, array( 'class' ) );
Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'class' => 'IPS\downloads\File', 'link' => 'downloads_files' ), 2, array( 'app', 'link', 'class' ) );
Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'class' => 'IPS\downloads\File\Review', 'link' => 'downloads_reviews' ), 2, array( 'app', 'link', 'class' ) );
return array( );
}
@@ -230,8 +251,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;
@@ -259,10 +280,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;
}
@@ -298,7 +319,7 @@ class _Xenforo extends \IPS\convert\Software
'cf_max_input' => $row['max_length'],
'cf_input_format' => $inputFormat,
'cf_position' => $row['display_order'],
'cf_multiple' => ( \in_array( $row['field_type'], array( 'checkbox', 'multiselect' ) ) ) ? 1 : 0
'cf_multiple' => ( in_array( $row['field_type'], array( 'checkbox', 'multiselect' ) ) ) ? 1 : 0
);
$libraryClass->convertDownloadsCfield( $info );
@@ -383,7 +404,7 @@ class _Xenforo extends \IPS\convert\Software
{
$prefix = $this->getPhrase( "thread_prefix_{$row['thread_prefix_id']}", "thread_prefix.{$row['thread_prefix_id']}" );
if ( \is_null( $prefix ) )
if ( is_null( $prefix ) )
{
$prefix = '';
}
@@ -455,7 +476,7 @@ class _Xenforo extends \IPS\convert\Software
$featured = 1;
}
catch( \UnderflowException $e ) {}
catch( UnderflowException $e ) {}
$info = array(
'file_id' => $row['resource_id'],
@@ -493,9 +514,9 @@ class _Xenforo extends \IPS\convert\Software
{
$file_data = $this->db->select( '*', 'xf_attachment', array( "xf_attachment.content_type=? AND xf_attachment.content_id=?", 'resource_version', $record['resource_version_id'] ) )->join( 'xf_attachment_data', "xf_attachment.data_id = xf_attachment_data.data_id" )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
$this->app->log( 'xenforo_resource_missing_record', __METHOD__, \IPS\convert\App::LOG_WARNING, $record['resource_update_id'] );
$this->app->log( 'xenforo_resource_missing_record', __METHOD__, App::LOG_WARNING, $record['resource_update_id'] );
continue;
}
@@ -525,9 +546,9 @@ class _Xenforo extends \IPS\convert\Software
);
}
}
catch( \UnderflowException $e )
catch( UnderflowException $e )
{
$this->app->log( 'xenforo_resource_missing_screenshot', __METHOD__, \IPS\convert\App::LOG_WARNING, $record['resource_update_id'] );
$this->app->log( 'xenforo_resource_missing_screenshot', __METHOD__, App::LOG_WARNING, $record['resource_update_id'] );
}
}
@@ -536,9 +557,9 @@ class _Xenforo extends \IPS\convert\Software
{
$field_type = $this->db->select( 'field_type', 'xf_' . static::$tablePrefix . 'resource_field', array( "field_id=?", $key ) )->first();
if ( \in_array( $field_type, array( 'checkbox', 'multiselect' ) ) )
if ( in_array( $field_type, array( 'checkbox', 'multiselect' ) ) )
{
$cfields[$key] = static::$isLegacy ? json_encode( \unserialize( $value ) ) : $value;
$cfields[$key] = static::$isLegacy ? json_encode( unserialize( $value ) ) : $value;
}
else
{
@@ -652,13 +673,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( '#/(resources/categories|resources)/(.+?)\.([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
if( preg_match( '#/(resources/categories|resources)/(.+?)\.([0-9]+)#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
{
$oldId = (int) $matches[3];
@@ -684,20 +705,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' ) )
{
@@ -705,7 +726,7 @@ class _Xenforo extends \IPS\convert\Software
}
}
}
catch( \Exception $e )
catch( Exception $e )
{
return NULL;
}