Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

@@ -20,6 +20,54 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
class _Xenforo extends \IPS\convert\Software
{
/**
* @brief The similarities between XF1 and XF2 are close enough that we can use the same converter
*/
public static $isLegacy = NULL;
/**
* @brief XF2 Has prefixes on RM tables
*/
public static $tablePrefix = '';
/**
* Constructor
*
* @param \IPS\convert\App The application to reference for database and other information.
* @param bool Establish a DB connection
* @return void
* @throws \InvalidArgumentException
*/
public function __construct( \IPS\convert\App $app, $needDB=TRUE )
{
$return = parent::__construct( $app, $needDB );
if ( $needDB )
{
try
{
/* Is this XF1 or XF2 */
if ( static::$isLegacy === NULL )
{
$version = $this->db->select( 'MAX(version_id)', 'xf_template', array( "addon_id=?", 'XF' ) )->first();
if ( $version < 2000010 )
{
static::$isLegacy = TRUE;
}
else
{
static::$tablePrefix = 'rm_';
static::$isLegacy = FALSE;
}
}
}
catch( \Exception $e ) {} # If we can't query, we won't be able to do anything anyway
}
return $return;
}
/**
* Software Name
*
@@ -28,7 +76,7 @@ class _Xenforo extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "XenForo Resource Manager";
return "XenForo Resource Manager (1.5.x/2.0.x)";
}
/**
@@ -51,24 +99,56 @@ class _Xenforo extends \IPS\convert\Software
{
return array(
'convertDownloadsCfields' => array(
'table' => 'xf_resource_field',
'table' => 'xf_' . static::$tablePrefix . 'resource_field',
'where' => NULL
),
'convertDownloadsCategories' => array(
'table' => 'xf_resource_category',
'table' => ( static::$isLegacy ? 'xf_resource_category' : 'xf_rm_category' ),
'where' => NULL
),
'convertDownloadsFiles' => array(
'table' => 'xf_resource',
'where' => array( "is_fileless=?", 0 )
'table' => 'xf_' . static::$tablePrefix . 'resource',
'where' => static::$isLegacy ? array( "is_fileless=?", 0 ) : array( 'resource_type=?', 'download' )
),
'convertDownloadsReviews' => array(
'table' => 'xf_resource_rating',
'table' => 'xf_' . static::$tablePrefix . 'resource_rating',
'where' => NULL
)
);
}
/**
* Count Source Rows for a specific step
*
* @param string $table The table containing the rows to count.
* @param array|NULL $where WHERE clause to only count specific rows, or NULL to count all.
* @param bool $recache Skip cache and pull directly (updating cache)
* @return integer
* @throws \IPS\convert\Exception
*/
public function countRows( $table, $where=NULL, $recache=FALSE )
{
switch( $table )
{
case 'xf_resource_field':
/* We need to do this for the connection check because all tables have different names in XF2 */
if( $this->db->checkForTable( 'xf_resource_field' ) )
{
return $this->db->select( 'COUNT(*)', 'xf_resource_field' )->first();
}
elseif( $this->db->checkForTable( 'xf_rm_resource_field' ) )
{
return $this->db->select( 'COUNT(*)', 'xf_rm_resource_field' )->first();
}
break;
default:
return parent::countRows( $table, $where, $recache );
break;
}
}
/**
* Requires Parent
*
@@ -153,13 +233,15 @@ class _Xenforo extends \IPS\convert\Software
/**
* Helper to fetch a xenforo phrase
*
* @param string $title Phrase
* @param string $xfOneTitle XF1 Phrase title
* @param string $xfTwoTitle XF2 Phrase Title
* @return string|null
*/
protected function getPhrase( $title )
protected function getPhrase( $xfOneTitle, $xfTwoTitle )
{
try
{
$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 )
@@ -177,15 +259,26 @@ class _Xenforo extends \IPS\convert\Software
{
$libraryClass = $this->getLibrary();
foreach( $this->fetch( 'xf_resource_field', 'field_id' ) AS $row )
foreach( $this->fetch( 'xf_' . static::$tablePrefix . 'resource_field', 'field_id' ) AS $row )
{
$inputFormat = '';
if( $row['match_type'] == 'regex' AND static::$isLegacy === FALSE )
{
$inputFormat = ( $row['match_type'] == 'regex' ) ? '/' . $row['match_regex'] .'/i' : '';
}
elseif( $row['match_type'] == 'regex' )
{
$json = json_decode( $row['match_params'] , TRUE );
$inputFormat = '/' . $json['regex'] .'/i';
}
$info = array(
'cf_id' => $row['field_id'],
'cf_type' => $this->_mapFieldType( $row['field_type'], $row['match_type'] ),
'cf_content' => \unserialize( $row['field_choices'] ),
'cf_content' => static::$isLegacy ? \unserialize( $row['field_choices'] ) : json_decode( $row['field_choices'], TRUE ),
'cf_not_null' => $row['required'],
'cf_max_input' => $row['max_length'],
'cf_input_format' => ( $row['match_type'] == 'regex' ) ? '/' . $row['match_regex'] .'/i' : '',
'cf_input_format' => $inputFormat,
'cf_position' => $row['display_order'],
'cf_multiple' => ( in_array( $row['field_type'], array( 'checkbox', 'multiselect' ) ) ) ? 1 : 0
);
@@ -255,11 +348,11 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass::setKey( 'resource_category_id' );
foreach( $this->fetch( 'xf_resource_category', 'resource_category_id' ) AS $row )
foreach( $this->fetch( ( static::$isLegacy ? 'xf_resource_category' : 'xf_rm_category' ), 'resource_category_id' ) AS $row )
{
/* Custom Fields for this category */
$ccfields = array();
foreach( $this->db->select( 'field_id', 'xf_resource_field_category', array( "resource_category_id=?", $row['resource_category_id'] ) ) AS $field )
foreach( $this->db->select( 'field_id', ( static::$isLegacy ? 'xf_resource_field_category' : 'xf_rm_category_field' ), array( "resource_category_id=?", $row['resource_category_id'] ) ) AS $field )
{
$ccfields[] = $field;
}
@@ -268,7 +361,7 @@ class _Xenforo extends \IPS\convert\Software
$prefix = '';
if ( $row['thread_prefix_id'] AND $row['thread_node_id'] )
{
$prefix = $this->getPhrase( "thread_prefix_{$row['thread_prefix_id']}" );
$prefix = $this->getPhrase( "thread_prefix_{$row['thread_prefix_id']}", "thread_prefix.{$row['thread_prefix_id']}" );
if ( is_null( $prefix ) )
{
@@ -279,8 +372,8 @@ class _Xenforo extends \IPS\convert\Software
$info = array(
'cid' => $row['resource_category_id'],
'cparent' => $row['parent_category_id'],
'cname' => $row['category_title'],
'cdesc' => $row['category_description'],
'cname' => isset( $row['category_title'] ) ? $row['category_title'] : $row['title'],
'cdesc' => isset( $row['category_description'] ) ? $row['category_description'] : $row['description'],
'copen' => ( $row['allow_local'] OR $row['allow_external'] ) ? 1 : 0,
'cposition' => $row['display_order'],
'ccfields' => $ccfields,
@@ -291,7 +384,7 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass->convertDownloadsCategory( $info );
/* Follows */
foreach( $this->db->select( '*', 'xf_resource_category_watch', array( "notify_on=? AND resource_category_id=?", 'resource', $row['resource_category_id'] ) ) AS $follow )
foreach( $this->db->select( '*', ( static::$isLegacy ? 'xf_resource_category_watch' : 'xf_rm_category_watch' ), array( "notify_on=? AND resource_category_id=?", 'resource', $row['resource_category_id'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'downloads',
@@ -305,8 +398,7 @@ class _Xenforo extends \IPS\convert\Software
'follow_notify_meta' => '',
'follow_notify_freq' => ( $follow['send_alert'] OR $follow['send_email'] ) ? 'immediate' : 'none',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
'follow_visible' => 1
) );
}
@@ -325,21 +417,21 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass::setKey( 'resource_id' );
foreach( $this->fetch( 'xf_resource', 'resource_id', array( "is_fileless=?", 0 ) ) AS $row )
foreach( $this->fetch( 'xf_' . static::$tablePrefix . 'resource', 'resource_id', ( static::$isLegacy ? array( "is_fileless=?", 0 ) : array( 'resource_type=?', 'download' ) ) ) AS $row )
{
/* Latest Version Stuff */
$latest = $this->db->select( '*', 'xf_resource_update', array( "xf_resource_update.resource_id=?", $row['resource_id'] ), "xf_resource_update.post_date DESC" )
->join( 'xf_resource_version', "xf_resource_update.resource_update_id = xf_resource_version.resource_update_id" )
$latest = $this->db->select( '*', 'xf_' . static::$tablePrefix . 'resource_update', array( "xf_" . static::$tablePrefix . "resource_update.resource_id=?", $row['resource_id'] ), "xf_" . static::$tablePrefix . "resource_update.post_date DESC" )
->join( 'xf_' . static::$tablePrefix . 'resource_version', "xf_" . static::$tablePrefix . "resource_update.post_date = xf_" . static::$tablePrefix . "resource_version.release_date" )
->first();
$latest_version = $latest['version_string'];
$latest_changelog = $latest['message'];
$latestVersion = $latest['version_string'];
$latestChangelog = $latest['message'];
/* Featured */
$featured = 0;
try
{
$this->db->select( '*', 'xf_resource_feature', array( "resource_id=?", $row['resource_id'] ) )->first();
$this->db->select( '*', 'xf_' . static::$tablePrefix . 'resource_feature', array( "resource_id=?", $row['resource_id'] ) )->first();
$featured = 1;
}
@@ -350,19 +442,20 @@ class _Xenforo extends \IPS\convert\Software
'file_desc' => $row['tag_line'],
'file_name' => $row['title'],
'file_cat' => $row['resource_category_id'],
'file_downloads' => $this->db->select( 'COUNT(*)', 'xf_resource_download', array( 'resource_id=?', $row['resource_id'] ) )->first(),
'file_downloads' => $this->db->select( 'COUNT(*)', 'xf_' . static::$tablePrefix . 'resource_download', array( 'resource_id=?', $row['resource_id'] ) )->first(),
'file_reviews' => $row['review_count'],
'file_submitted' => $row['resource_date'],
'file_updated' => $row['last_update'],
'file_submitter' => $row['user_id'],
'file_topicid' => $row['discussion_thread_id'],
'file_version' => $latest_version,
'file_changelog' => $latest_changelog,
'file_version' => $latestVersion,
'file_changelog' => $latestChangelog,
'file_featured' => $featured,
);
$records = array();
$recordit = $this->db->select( '*', 'xf_resource_update', array( "xf_resource_update.resource_id=?", $row['resource_id'] ) )->join( 'xf_resource_version', "xf_resource_update.resource_update_id = xf_resource_version.resource_update_id" );
$recordit = $this->db->select( '*', 'xf_' . static::$tablePrefix . 'resource_update', array( "xf_" . static::$tablePrefix . "resource_update.resource_id=?", $row['resource_id'] ) )->join( 'xf_' . static::$tablePrefix . 'resource_version', "xf_" . static::$tablePrefix . "resource_update.post_date = xf_" . static::$tablePrefix . "resource_version.release_date" );
foreach( $recordit AS $record )
{
if ( $record['download_url'] )
@@ -419,24 +512,24 @@ class _Xenforo extends \IPS\convert\Software
}
$cfields = array();
foreach( $this->db->select( 'field_id, field_value', 'xf_resource_field_value', array( "resource_id=?", $row['resource_id'] ) )->setKeyField( 'field_id' )->setValueField( 'field_value' ) AS $key => $value )
foreach( $this->db->select( 'field_id, field_value', 'xf_' . static::$tablePrefix . 'resource_field_value', array( "resource_id=?", $row['resource_id'] ) )->setKeyField( 'field_id' )->setValueField( 'field_value' ) AS $key => $value )
{
$field_type = $this->db->select( 'field_type', 'xf_resource_field', array( "field_id=?", $key ) )->first();
$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' ) ) )
{
$cfields[$key] = json_encode( \unserialize( $value ) );
$cfields[$key] = static::$isLegacy ? json_encode( \unserialize( $value ) ) : $value;
}
else
{
$cfields[$key] = $value;
}
}
$libraryClass->convertDownloadsFile( $info, $records, $cfields );
/* Follows */
foreach( $this->db->select( '*', 'xf_resource_watch', array( "resource_id=?", $row['resource_id'] ) ) AS $follow )
foreach( $this->db->select( '*', 'xf_' . static::$tablePrefix . 'resource_watch', array( "resource_id=?", $row['resource_id'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'downloads',
@@ -450,8 +543,7 @@ class _Xenforo extends \IPS\convert\Software
'follow_notify_meta' => '',
'follow_notify_freq' => ( $follow['email_subscribe'] ) ? 'immediate' : 'none',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
'follow_visible' => 1
) );
}
@@ -470,7 +562,7 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass::setKey( 'resource_rating_id' );
foreach( $this->fetch( 'xf_resource_rating', 'resource_rating_id' ) AS $row )
foreach( $this->fetch( 'xf_' . static::$tablePrefix . 'resource_rating', 'resource_rating_id' ) AS $row )
{
switch( $row['rating_state'] )
{
@@ -503,7 +595,7 @@ class _Xenforo extends \IPS\convert\Software
if ( $this->app->_session['more_info']['convertDownloadsReviews']['convert_author_replies_to_comments'] AND $row['author_response'] )
{
/* Get Resource */
$resource = $this->db->select( '*', 'xf_resource', array( "resource_id=?", $row['resource_id'] ) )->first();
$resource = $this->db->select( '*', 'xf_' . static::$tablePrefix . 'resource', array( "resource_id=?", $row['resource_id'] ) )->first();
$member = $this->db->select( '*', 'xf_user', array( "user_id=?", $row['user_id'] ) )->first();
$post = "<blockquote class=\"ipsQuote\" data-ipsQuote-username=\"{$member['username']}\">{$row['message']}</blockquote><p>{$row['author_response']}</p>";
@@ -519,4 +611,69 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass->setLastKeyValue( $row['resource_rating_id'] );
}
}
/**
* Check if we can redirect the legacy URLs from this software to the new locations
*
* @return NULL|\IPS\Http\Url
*/
public function checkRedirects()
{
$url = \IPS\Request::i()->url();
if( preg_match( '#/(resources/categories|resources)/(.+?)\.([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$oldId = (int) $matches[3];
switch( $matches[1] )
{
case 'resources/categories':
$class = '\IPS\downloads\Category';
$types = array( 'downloads_categories' );
break;
case 'resources':
$class = '\IPS\downloads\File';
$types = array( 'downloads_files' );
break;
}
}
if( isset( $class ) )
{
try
{
try
{
$data = (string) $this->app->getLink( $oldId, $types );
}
catch( \OutOfRangeException $e )
{
$data = (string) $this->app->getLink( $oldId, $types, FALSE, TRUE );
}
$item = $class::load( $data );
if( $item instanceof \IPS\Content )
{
if( $item->canView() )
{
return $item->url();
}
}
elseif( $item instanceof \IPS\Node\Model )
{
if( $item->can( 'view' ) )
{
return $item->url();
}
}
}
catch( \Exception $e )
{
return NULL;
}
}
return NULL;
}
}