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 = 'xengallery_';
/**
* 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 = 'xf_mg_';
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 Media Gallery";
return "XenForo Media Gallery (1.5.x/2.0.x)";
}
/**
@@ -51,24 +99,56 @@ class _Xenforo extends \IPS\convert\Software
{
return array(
'convertGalleryCategories' => array(
'table' => 'xengallery_category',
'table' => static::$tablePrefix . 'category',
'where' => NULL
),
'convertGalleryAlbums' => array(
'table' => 'xengallery_album',
'table' => static::$tablePrefix . 'album',
'where' => NULL,
),
'convertGalleryImages' => array(
'table' => 'xengallery_media',
'table' => ( static::$isLegacy ? 'xengallery_media' : 'xf_mg_media_item' ),
'where' => NULL,
),
'convertGalleryComments' => array(
'table' => 'xengallery_comment',
'table' => static::$tablePrefix . 'comment',
'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 'xengallery_category':
/* We need to do this for the connection check because all tables have different names in XF2 */
if( $this->db->checkForTable( 'xengallery_category' ) )
{
return $this->db->select( 'COUNT(*)', 'xengallery_category' )->first();
}
elseif( $this->db->checkForTable( 'xf_mg_category' ) )
{
return $this->db->select( 'COUNT(*)', 'xf_mg_category' )->first();
}
break;
default:
return parent::countRows( $table, $where, $recache );
break;
}
}
/**
* Uses Prefix
*
@@ -190,6 +270,7 @@ class _Xenforo extends \IPS\convert\Software
{
/* Content Rebuilds */
\IPS\Task::queue( 'convert', 'RebuildGalleryImages', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'gallery_comments', 'class' => 'IPS\gallery\Image\Comment' ), 2, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\gallery\Image' ), 3, array( 'class' ) );
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Album', 'count' => 0 ), 4, array( 'class' ) );
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Category', 'count' => 0 ), 5, array( 'class' ) );
@@ -203,13 +284,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 )
@@ -229,19 +312,19 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass::setKey( 'category_id' );
foreach( $this->fetch( 'xengallery_category', 'category_id' ) AS $row )
foreach( $this->fetch( static::$tablePrefix . 'category', 'category_id' ) AS $row )
{
$libraryClass->convertGalleryCategory( array(
'category_id' => $row['category_id'],
'category_name' => $row['category_title'],
'category_desc' => $row['category_description'],
'category_name' => isset( $row['category_title'] ) ? $row['category_title'] : $row['title'],
'category_desc' => isset( $row['category_description'] ) ? $row['category_description'] : $row['description'],
'category_parent_id' => $row['parent_category_id'],
'category_count_imgs' => $row['category_media_count'],
'category_count_imgs' => isset( $row['category_media_count'] ) ? $row['category_media_count'] : $row['category_media_count'],
'category_position' => $row['display_order']
) );
/* Follows */
foreach( $this->db->select( '*', 'xengallery_category_watch', array( "notify_on=? AND category_id=?", 'media', $row['category_id'] ) ) AS $follow )
foreach( $this->db->select( '*', static::$tablePrefix . 'category_watch', array( "notify_on=? AND category_id=?", 'media', $row['category_id'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'gallery',
@@ -256,7 +339,6 @@ class _Xenforo extends \IPS\convert\Software
'follow_notify_freq' => ( $follow['send_alert'] OR $follow['send_email'] ) ? 'immediate' : 'none',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
}
@@ -273,20 +355,32 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass::setKey( 'album_id' );
foreach( $this->fetch( 'xengallery_album', 'album_id' ) AS $row )
foreach( $this->fetch( static::$tablePrefix . 'album', 'album_id' ) AS $row )
{
try
if( static::$isLegacy )
{
$perm = $this->db->select( '*', 'xengallery_album_permission', array( "album_id=? AND permission=?", $row['album_id'], 'view' ) )->first();
try
{
$perm = $this->db->select( '*', 'xengallery_album_permission', array( "album_id=? AND permission=?", $row['album_id'], 'view' ) )->first();
$perm['share_users'] = \unserialize( $perm['share_users'] );
}
catch( \UnderflowException $e )
{
/* If the permission row is missing for some reason, err on the side of caution and set this album private */
$perm = array(
'album_id' => $row['album_id'],
'permission' => 'view',
'access_type' => 'private',
'share_users' => array()
);
}
}
catch( \UnderflowException $e )
/* XF2 */
else
{
/* If the permission row is missing for some reason, err on the side of caution and set this album private */
$perm = array(
'album_id' => $row['album_id'],
'permission' => 'view',
'access_type' => 'private',
'share_users' => \serialize( array() ),
'access_type' => $row['view_privacy'],
'share_users' => json_decode( $row['view_users'], TRUE )
);
}
@@ -297,7 +391,7 @@ class _Xenforo extends \IPS\convert\Software
{
/* Specific members */
case 'shared':
$users = \unserialize( $perm['share_users'] );
$users = $perm['share_users'];
$socialgroup['members'] = array();
if ( count( $users ) )
@@ -340,14 +434,14 @@ class _Xenforo extends \IPS\convert\Software
$info = array(
'album_id' => $row['album_id'],
'album_owner_id' => $row['album_user_id'],
'album_description' => $row['album_description'],
'album_name' => $row['album_title'],
'album_description' => isset( $row['album_description'] ) ? $row['album_description'] : $row['description'],
'album_name' => isset( $row['album_title'] ) ? $row['album_title'] : $row['title'],
'album_type' => $type,
'album_count_imgs' => $row['album_media_count'],
'album_count_comments' => $row['album_comment_count'],
'album_rating_aggregate' => $row['album_rating_avg'],
'album_rating_count' => $row['album_rating_count'],
'album_rating_total' => $row['album_rating_sum'],
'album_count_imgs' => isset( $row['album_media_count'] ) ? $row['album_media_count'] : $row['media_count'],
'album_count_comments' => isset( $row['album_comment_count'] ) ? $row['album_comment_count'] : $row['comment_count'],
'album_rating_aggregate' => isset( $row['album_rating_avg'] ) ? $row['album_rating_avg'] : $row['rating_avg'],
'album_rating_count' => isset( $row['album_rating_count'] ) ? $row['album_rating_count'] : $row['rating_count'],
'album_rating_total' => isset( $row['album_rating_sum'] ) ? $row['album_rating_sum'] : $row['ating_sum'],
);
$category = $this->app->_session['more_info']['convertGalleryAlbums']['members_gallery_category'];
@@ -359,7 +453,7 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass->convertGalleryAlbum( $info, $socialgroup, $category );
/* Follows */
foreach( $this->db->select( '*', 'xengallery_album_watch', array( "notify_on=? AND album_id=?", 'media', $row['album_id'] ) ) AS $follow )
foreach( $this->db->select( '*', static::$tablePrefix . 'album_watch', array( "notify_on=? AND album_id=?", 'media', $row['album_id'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'gallery',
@@ -374,7 +468,6 @@ class _Xenforo extends \IPS\convert\Software
'follow_notify_freq' => ( $follow['send_alert'] OR $follow['send_email'] ) ? 'immediate' : 'none',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -393,13 +486,27 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass::setKey( 'media_id' );
foreach( $this->fetch( 'xengallery_media', 'media_id' ) AS $row )
foreach( $this->fetch( static::$isLegacy ? 'xf_gallery_media' : 'xf_mg_media_item', 'media_id' ) AS $row )
{
/* Exif */
$exif = array();
foreach( $this->db->select( 'exif_name, exif_value', 'xengallery_exif', array( "media_id=?", $row['media_id'] ) )->setKeyField( 'exif_name' )->setValueField( 'exif_value' ) AS $key => $value )
if( static::$isLegacy )
{
$exif[$key] = $value;
foreach( $this->db->select( 'exif_name, exif_value', 'xengallery_exif', array( "media_id=?", $row['media_id'] ) )->setKeyField( 'exif_name' )->setValueField( 'exif_value' ) AS $key => $value )
{
$exif[ $key ] = $value;
}
}
/* XF2 */
else
{
foreach( json_decode( $row['exif_data'], TRUE ) AS $key => $value )
{
foreach( $value as $subKey => $subValue )
{
$exif[ $key . '.' . $subKey ] = $subValue;
}
}
}
/* IP Address */
@@ -417,9 +524,10 @@ class _Xenforo extends \IPS\convert\Software
{
/* Normal image upload */
case 'image_upload':
case 'image':
try
{
$file_data = $this->db->select( '*', 'xf_attachment', array( "xf_attachment.content_type=? AND xf_attachment.content_id=?", 'xengallery_media', $row['media_id'] ) )
$file_data = $this->db->select( '*', 'xf_attachment', array( "xf_attachment.content_type=? AND xf_attachment.content_id=?", ( static::$isLegacy ? 'xengallery_media' : 'xfmg_media' ), $row['media_id'] ) )
->join( 'xf_attachment_data', 'xf_attachment.data_id = xf_attachment_data.data_id' )
->first();
}
@@ -433,15 +541,17 @@ class _Xenforo extends \IPS\convert\Software
$group = floor( $file_data['data_id'] / 1000 );
$path = rtrim( $this->app->_session['more_info']['convertGalleryImages']['file_location'], '/' ) . '/' . $group . '/' . $file_data['data_id'] . '-' . $file_data['file_hash'] . '.data';
$file_name = $file_data['filename'];
$description = $row['media_description'];
$description = isset( $row['media_description'] ) ? $row['media_description'] : $row['description'];
break;
/* Video Embed */
case 'video_embed':
case 'embed':
$path = $this->app->_session['more_info']['convertGalleryImages']['media_thumb_location'];
/* We need to figure out what service we came from, and the video ID */
$matches = array();
preg_match( '/\[media=(.*?)\](.*?)\[\/media\]/i', $row['media_tag'], $matches );
$service = $matches[1];
$video_id = $matches[2];
@@ -460,7 +570,7 @@ class _Xenforo extends \IPS\convert\Software
continue 2;
}
$description = $em . "<br>" . $row['media_description'];
$description = $em . "<br>" . isset( $row['media_description'] ) ? $row['media_description'] : $row['description'];
break;
}
@@ -470,8 +580,8 @@ class _Xenforo extends \IPS\convert\Software
'image_album_id' => $row['album_id'],
'image_category_id' => $row['category_id'],
'image_member_id' => $row['user_id'],
'image_caption' => $row['media_title'],
'image_views' => $row['media_view_count'],
'image_caption' => isset( $row['media_title'] ) ? $row['media_title'] : $row['title'],
'image_views' => isset( $row['media_view_count'] ) ? $row['media_view_count'] : $row['view_count'],
'image_comments' => $row['comment_count'],
'image_ratings_total' => $row['rating_sum'],
'image_ratings_count' => $row['rating_count'],
@@ -488,9 +598,9 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass->convertGalleryImage( $info, $path );
/* Warnings */
foreach( $this->db->select( '*', 'xf_warning', array( "content_type=? AND content_id=?", 'xengallery_media', $row['media_id'] ) ) AS $warn )
foreach( $this->db->select( '*', 'xf_warning', array( "content_type=? AND content_id=?", ( static::$isLegacy ? 'xengallery_media' : 'xfmg_media' ), $row['media_id'] ) ) AS $warn )
{
$libraryClass->convertWarnLog( array(
$warnId = $libraryClass->convertWarnLog( array(
'wl_id' => $warn['warning_id'],
'wl_member' => $warn['user_id'],
'wl_moderator' => $warn['warning_user_id'],
@@ -499,6 +609,17 @@ class _Xenforo extends \IPS\convert\Software
'wl_note_member' => $warn['title'],
'wl_note_mods' => $warn['notes'],
) );
/* Add a member history record for this member */
$libraryClass->convertMemberHistory( array(
'log_id' => 'w' . $warn['warning_id'],
'log_member' => $warn['user_id'],
'log_by' => $warn['warning_user_id'],
'log_type' => 'warning',
'log_data' => array( 'wid' => $warnId ),
'log_date' => $warn['warning_date']
)
);
}
/* Reputation */
@@ -520,7 +641,7 @@ class _Xenforo extends \IPS\convert\Software
}
/* Follows */
foreach( $this->db->select( '*', 'xengallery_media_watch', array( "media_id=?", $row['media_id'] ) ) AS $follow )
foreach( $this->db->select( '*', static::$tablePrefix . 'media_watch', array( "media_id=?", $row['media_id'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'gallery',
@@ -535,7 +656,6 @@ class _Xenforo extends \IPS\convert\Software
'follow_notify_freq' => ( $follow['send_alert'] OR $follow['send_email'] ) ? 'immediate' : 'none',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -582,7 +702,7 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass::setKey( 'comment_id' );
foreach( $this->fetch( 'xengallery_comment', 'comment_id', array( "content_type=?", 'media' ) ) AS $row )
foreach( $this->fetch( static::$tablePrefix . 'comment', 'comment_id', array( "content_type=?", 'media' ) ) AS $row )
{
/* IP Address */
try
@@ -640,9 +760,9 @@ class _Xenforo extends \IPS\convert\Software
}
/* Warnings */
foreach( $this->db->select( '*', 'xf_warning', array( "content_type=? AND content_id=?", 'xengallery_comment', $row['comment_id'] ) ) AS $warn )
foreach( $this->db->select( '*', 'xf_warning', array( "content_type=? AND content_id=?", ( static::$isLegacy ? 'xengallery_comment' : 'xfmg_comment' ), $row['comment_id'] ) ) AS $warn )
{
$libraryClass->convertWarnLog( array(
$warnId = $libraryClass->convertWarnLog( array(
'wl_id' => $warn['warning_id'],
'wl_member' => $warn['user_id'],
'wl_moderator' => $warn['warning_user_id'],
@@ -651,6 +771,17 @@ class _Xenforo extends \IPS\convert\Software
'wl_note_member' => $warn['title'],
'wl_note_mods' => $warn['notes'],
) );
/* Add a member history record for this member */
$libraryClass->convertMemberHistory( array(
'log_id' => 'w' . $warn['warning_id'],
'log_member' => $warn['user_id'],
'log_by' => $warn['warning_user_id'],
'log_type' => 'warning',
'log_data' => array( 'wid' => $warnId ),
'log_date' => $warn['warning_date']
)
);
}
$libraryClass->setLastKeyValue( $row['comment_id'] );