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

@@ -320,7 +320,6 @@ class _Vbulletin extends \IPS\convert\Software
'follow_notify_freq' => $frequency,
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -455,7 +454,6 @@ class _Vbulletin extends \IPS\convert\Software
'follow_notify_freq' => $frequency,
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -560,7 +558,17 @@ class _Vbulletin extends \IPS\convert\Software
{
if ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) )
{
$filedata = $this->db->select( '*', 'filedata', array( "filedataid=?", $attachment['filedataid'] ) )->first();
try
{
$filedata = $this->db->select( '*', 'filedata', array( "filedataid=?", $attachment['filedataid'] ) )->first();
}
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'] );
continue;
}
}
else
{
@@ -597,16 +605,24 @@ class _Vbulletin extends \IPS\convert\Software
}
$attach_id = $libraryClass->convertAttachment( $info, $map, $path, $data );
/* 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();
if ( preg_match( "/\[ATTACH(.+?)?\]".$attachment['attachmentid']."\[\/ATTACH\]/i", $post ) )
if ( $attach_id !== FALSE )
{
$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 ) );
try
{
/* 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();
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 ) );
}
}
catch( \UnderflowException $e ) {}
catch( \OutOfRangeException $e ) {}
}
$libraryClass->setLastKeyValue( $attachment['attachmentid'] );
@@ -200,7 +200,7 @@ class _Mybb extends \IPS\convert\Software
'event_content' => $row['description'],
'event_saved' => $row['dateline'],
'event_start_date' => \IPS\calendar\Date::ts( $row['starttime'] ),
'event_end_date' => \IPS\calendar\Date::ts( $row['endtime'] ),
'event_end_date' => $row['endtime'] ? \IPS\calendar\Date::ts( $row['endtime'] ) : NULL,
'event_approved' => $row['visible'],
'event_recurring' => $recurring,
) );
@@ -237,7 +237,7 @@ class _Vbulletin extends \IPS\convert\Software
'event_content' => $event['event'],
'event_saved' => $event['dateline'],
'event_start_date' => \IPS\calendar\Date::ts( $event['dateline_from'] ),
'event_end_date' => \IPS\calendar\Date::ts( $event['dateline_to'] ),
'event_end_date' => $event['dateline_to'] ? \IPS\calendar\Date::ts( $event['dateline_to'] ) : NULL,
'event_approved' => $event['visible'],
'event_recurring' => $recurring
);
@@ -462,7 +462,7 @@ class _Vbulletin extends \IPS\convert\Software
'rating_real' => $nodeinfo['ratingtotal'],
'rating_hits' => $nodeinfo['ratingnum'],
'rating_value' => $nodeinfo['rating'],
'record_locked' => $node['comments_enabled'],
'record_locked' => ( $node['comments_enabled'] ) ? 0 : 1,
'record_views' => $nodeinfo['viewcount'],
'record_allow_comments' => $node['comments_enabled'],
'record_saved' => $node['publishdate'],
@@ -498,7 +498,11 @@ class _Vbulletin extends \IPS\convert\Software
// Uncomment this once Tags are implemented for the cms;
# \IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'cms_custom_database_' . $database, 'class' => 'IPS\cms\Records' . $database ), 3, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'cms_custom_database_' . $database, 'class' => 'IPS\cms\Records' . $database ), 2, array( 'app', 'link', 'class' ) );
try
{
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'cms_custom_database_' . $database, 'class' => 'IPS\cms\Records' . $database ), 2, array( 'app', 'link', 'class' ) );
}
catch ( \OutOfRangeException $e ) {}
}
return array( "f_recount_cms_categories", "f_rebuild_cms_tags" );
@@ -184,6 +184,7 @@ class _Wordpress extends \IPS\convert\Software
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'cms_records', 'class' => 'IPS\cms\Records' . $database ), 3, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'cms_custom_database_' . $database, 'class' => 'IPS\cms\Records' . $database ), 2, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'cms_database_comments', 'class' => 'IPS\cms\Records\Comment' . $database ), 2, array( 'app', 'link', 'class' ) );
return array( "f_recount_cms_categories", "f_rebuild_cms_tags" );
}
@@ -28,7 +28,7 @@ class _Xenforo extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "XenForo Page Nodes";
return "XenForo Page Nodes (1.5.x/2.0.x)";
}
/**
@@ -87,24 +87,6 @@ class _Xenforo extends \IPS\convert\Software
return array( 'core' => array( 'xenforo' ) );
}
/**
* Helper to fetch a xenforo phrase
*
* @param string $title Phrase string
* @return string|null Phrase
*/
protected function getPhrase( $title )
{
try
{
return $this->db->select( 'phrase_text', 'xf_phrase', array( "title=?", $title ) )->first();
}
catch( \UnderflowException $e )
{
return NULL;
}
}
/**
* Convert CMS page
*
@@ -20,6 +20,16 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
class _Xenfororm 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 = '';
/**
* Software Name
*
@@ -28,7 +38,45 @@ class _Xenfororm extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "XenForo Resource Manager Articles";
return "XenForo Resource Manager Articles (1.5.x/2.0.x)";
}
/**
* 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;
}
/**
@@ -55,12 +103,12 @@ class _Xenfororm extends \IPS\convert\Software
'where' => NULL,
),
'convertCmsDatabaseCategories' => array(
'table' => 'xf_resource_category',
'table' => ( static::$isLegacy ? 'xf_resource_category' : 'xf_rm_category' ),
'where' => array( "allow_fileless=?", 1 )
),
'convertCmsDatabaseRecords' => array(
'table' => 'xf_resource',
'where' => array( "is_fileless=?", 1 )
'table' => 'xf_' . static::$tablePrefix . 'resource',
'where' => static::$isLegacy ? array( "is_fileless=?", 1 ) : array( 'resource_type=?', 'fileless' )
)
);
}
@@ -118,24 +166,6 @@ class _Xenfororm extends \IPS\convert\Software
return array( 'core' => array( 'xenforo' ) );
}
/**
* Helper to fetch a xenforo phrase
*
* @param string $title Phrase
* @return string|null
*/
protected function getPhrase( $title )
{
try
{
return $this->db->select( 'phrase_text', 'xf_phrase', array( "title=?", $title ) )->first();
}
catch( \UnderflowException $e )
{
return NULL;
}
}
/**
* Convert CMS databases
*
@@ -198,7 +228,7 @@ class _Xenfororm extends \IPS\convert\Software
$libraryClass::setKey( 'resource_category_id' );
foreach( $this->fetch( 'xf_resource_category', 'resource_category_id', array( 'allow_fileless=?', 1 ) ) AS $row )
foreach( $this->fetch( ( static::$isLegacy ? 'xf_resource_category' : 'xf_rm_category' ), 'resource_category_id', array( 'allow_fileless=?', 1 ) ) AS $row )
{
$forumoverride = 0;
$forumid = 0;
@@ -211,7 +241,8 @@ class _Xenfororm extends \IPS\convert\Software
$info = array(
'category_id' => $row['resource_category_id'],
'category_database_id' => 1,
'category_name' => $row['category_title'],
'category_name' => isset( $row['category_title'] ) ? $row['category_title'] : $row['title'],
'category_parent_id' => $row['parent_category_id'],
'category_position' => $row['display_order'],
'category_fields' => array( 'resource_title', 'resource_tagline', 'resource_content' ),
);
@@ -233,9 +264,9 @@ class _Xenfororm extends \IPS\convert\Software
$libraryClass::setKey( 'resource_id' );
foreach( $this->fetch( 'xf_resource', 'resource_id', array( 'is_fileless=?', 1 ) ) AS $row )
foreach( $this->fetch( 'xf_' . static::$tablePrefix . 'resource', 'resource_id', static::$isLegacy ? array( "is_fileless=?", 1 ) : array( 'resource_type=?', 'fileless' ) ) AS $row )
{
$post = $this->db->select( 'message, post_date', 'xf_resource_update', array( "resource_id=?", $row['resource_id'] ), "post_date DESC" )->first();
$post = $this->db->select( 'message, post_date', 'xf_' . static::$tablePrefix . 'resource_update', array( "resource_id=?", $row['resource_id'] ), "post_date DESC" )->first();
switch( $row['resource_state'] )
{
@@ -84,6 +84,30 @@ class _Expressionengine extends \IPS\convert\Software
);
}
/**
* Allows software to add additional menu row options
*
* @param array $rows Existing rows
* @return array
*/
public function extraMenuRows( $rows )
{
if( isset( $rows['convertPrivateMessageReplies'] ) )
{
$rows['convertPmAttachments'] = array(
'step_method' => 'convertPmAttachments',
'step_title' => 'convert_attachments',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_attachments' )->first(),
'source_rows' => $this->countRows( static::canConvert()['convertPmAttachments']['table'], static::canConvert()['convertPmAttachments']['where'] ),
'per_cycle' => 100,
'dependencies' => array( 'convertPrivateMessageReplies' ),
'link_type' => 'core_attachments',
);
}
return $rows;
}
/**
* Can we convert passwords from this software.
*
@@ -288,7 +312,7 @@ class _Expressionengine extends \IPS\convert\Software
\IPS\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 ), 4, array( 'app' ) );
\IPS\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" );
}
@@ -724,4 +748,39 @@ class _Expressionengine extends \IPS\convert\Software
return NULL;
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
$length = \strlen( $member->conv_password );
$providedHash = FALSE;
switch( $length )
{
/* MD5 */
case 32:
$providedHash = md5( $password );
break;
/* SHA1 */
case 40:
$providedHash = sha1( $password );
break;
/* SHA256 */
case 64:
$providedHash = hash( 'sha256', $password );
break;
/* SHA512 */
case 128:
$providedHash = hash( 'sha512', $password );
break;
}
return ( \IPS\Login::compareHashes( $member->conv_password, $providedHash ) ) ? TRUE : FALSE;
}
}
File diff suppressed because it is too large. Load diff
@@ -229,4 +229,32 @@ class _Joomla extends \IPS\convert\Software
$libraryClass->setLastKeyValue( $row['id'] );
}
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
/* Joomla 3 */
if( preg_match( '/^\$2[ay]\$(0[4-9]|[1-2][0-9]|3[0-1])\$[a-zA-Z0-9.\/]{53}/', $member->conv_password ) )
{
require_once \IPS\ROOT_PATH . "/applications/convert/sources/Login/PasswordHash.php";
$ph = new \PasswordHash( 8, TRUE );
return $ph->CheckPassword( $password, $member->conv_password ) ? TRUE : FALSE;
}
/* Joomla 2 */
if ( \IPS\Login::compareHashes( $member->conv_password, md5( $password . $member->misc ) ) )
{
return TRUE;
}
else
{
return FALSE;
}
}
}
@@ -283,10 +283,30 @@ class _Mybb extends \IPS\convert\Software
/* First Post Data */
\IPS\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' ) );
return array( "f_search_index_rebuild", "f_clear_caches", "f_rebuild_pms", "f_signatures_rebuild", "f_announce_rebuild" );
}
/**
* Fix post data
*
* @param string raw post data
* @return string parsed post data
*/
public static function fixPostData( $post )
{
/* Replace align tags with left/right/center/justify */
$post = preg_replace( '/\[align=(justify|left|right)\](.+?)\[\/align\]/i', '[$1]$2[/$1]', $post );
/* remove justify, since we don't support it */
$post = str_replace( array( '[justify]', '[/justify]' ), '', $post );
return $post;
}
/**
* Convert announcements
*
@@ -899,7 +919,7 @@ class _Mybb extends \IPS\convert\Software
/* Warnings */
foreach( $this->db->select( '*', 'warnings', array( "uid=? AND pid=?", $row['uid'], 0 ) ) AS $warning )
{
$libraryClass->convertWarnLog( array(
$warnId = $libraryClass->convertWarnLog( array(
'wl_id' => $warning['wid'],
'wl_member' => $warning['uid'],
'wl_moderator' => $warning['issuedby'],
@@ -909,6 +929,17 @@ class _Mybb extends \IPS\convert\Software
'wl_note_mods' => $warning['notes'],
'wl_expire_date' => $warning['expires'],
) );
/* Add a member history record for this member */
$libraryClass->convertMemberHistory( array(
'log_id' => 'w' . $warning['wid'],
'log_member' => $warning['uid'],
'log_by' => $warning['issuedby'],
'log_type' => 'warning',
'log_data' => array( 'wid' => $warnId ),
'log_date' => $warning['dateline']
)
);
}
$libraryClass->setLastKeyValue( $row['uid'] );
@@ -1078,4 +1109,23 @@ class _Mybb extends \IPS\convert\Software
return NULL;
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
if ( \IPS\Login::compareHashes( $member->conv_password, md5( md5( $member->misc ) . md5( $password ) ) ) )
{
return TRUE;
}
else
{
return FALSE;
}
}
}
@@ -7,7 +7,6 @@
* @package Invision Community
* @subpackage Converter
* @since 6 December 2016
* @note Only redirect scripts are supported right now
*/
namespace IPS\convert\Software\Core;
@@ -29,7 +28,7 @@ class _Photopost extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "Photopost";
return "Photopost (8.x)";
}
/**
@@ -46,11 +45,242 @@ class _Photopost extends \IPS\convert\Software
/**
* Content we can convert from this software.
*
* @return NULL
* @return array
*/
public static function canConvert()
{
return NULL;
return array(
'convertGroups' => array(
'table' => 'usergroups',
'where' => NULL,
),
'convertMembers' => array(
'table' => 'users',
'where' => NULL,
)
);
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertGroups',
'convertMembers'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertGroups':
$return['convertGroups'] = array();
$options = array();
$options['none'] = 'None';
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
{
$options[$group->g_id] = $group->name;
}
foreach( $this->db->select( '*', 'usergroups' ) AS $group )
{
\IPS\Member::loggedIn()->language()->words["map_group_{$group['groupid']}"] = $group['groupname'];
\IPS\Member::loggedIn()->language()->words["map_group_{$group['groupid']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_group_desc' );
$return['convertGroups']["map_group_{$group['groupid']}"] = array(
'field_class' => 'IPS\\Helpers\\Form\\Select',
'field_default' => NULL,
'field_required' => FALSE,
'field_extra' => array( 'options' => $options ),
'field_hint' => NULL,
);
}
break;
case 'convertMembers':
$return['convertMembers'] = array();
\IPS\Member::loggedIn()->language()->words['photo_location_desc'] = \IPS\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' => "The path to the folder where avatars are saved (no trailing slash - usually /path_to_photopost/data/avatars):",
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
);
/* And decide what to do about these... */
foreach( array( 'homepage', 'icq', 'aim', 'yahoo', 'location', 'interests', 'occupation', 'bio' ) AS $field )
{
\IPS\Member::loggedIn()->language()->words["field_{$field}"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field', FALSE, array( 'sprintf' => ucwords( $field ) ) );
\IPS\Member::loggedIn()->language()->words["field_{$field}_desc"] = \IPS\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' ),
),
'userSuppliedInput' => 'create_field'
),
'field_hint' => NULL
);
}
break;
}
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
}
/**
* Finish - Adds everything it needs to the queues and clears data store
*
* @return array Message to display
*/
public function finish()
{
/* Search Index Rebuild */
\IPS\Content\Search\Index::i()->rebuild();
/* Clear Cache and Store */
\IPS\Data\Store::i()->clearAll();
\IPS\Data\Cache::i()->clearAll();
/* Non-Content Rebuilds */
\IPS\Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_members', 'extension' => 'core_Signatures' ), 2, array( 'app', 'link', 'extension' ) );
/* Content Counts */
\IPS\Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
return array( "f_search_index_rebuild", "f_clear_caches", "f_signatures_rebuild" );
}
/**
* Convert groups
*
* @return void
*/
public function convertGroups()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'groupid' );
foreach( $this->fetch( 'usergroups', 'groupid' ) AS $row )
{
$info = array(
'g_id' => $row['groupid'],
'g_name' => $row['groupname']
);
$merge = $this->app->_session['more_info']['convertGroups']["map_group_{$row['groupid']}"] != 'none' ? $this->app->_session['more_info']['convertGroups']["map_group_{$row['groupid']}"] : NULL;
$libraryClass->convertGroup( $info, $merge );
$libraryClass->setLastKeyValue( $row['groupid'] );
}
/* Now check for group promotions */
if( count( $libraryClass->groupPromotions ) )
{
foreach( $libraryClass->groupPromotions as $groupPromotion )
{
$libraryClass->convertGroupPromotion( $groupPromotion );
}
}
}
/**
* Convert members
*
* @return void
*/
public function convertMembers()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'userid' );
foreach( $this->fetch( 'users', 'userid' ) AS $row )
{
$birthdayYear = $birthdayMonth = $birthdayDay = NULL;
/* Is there a birthdate? */
if( $row['birthday'] != '0000-00-00' )
{
list( $birthdayYear, $birthdayMonth, $birthdayDay ) = explode( '-', $row['birthday'] );
}
$info = array(
'member_id' => $row['userid'],
'email' => $row['email'],
'name' => $row['username'],
'md5_password' => $row['password'],
'member_group_id' => $row['usergroupid'],
'joined' => $row['joindate'] ?: NULL,
'ip_address' => $row['ipaddress'],
'last_visit' => $row['laston'],
'last_activity' => $row['laston'],
'bday_day' => $birthdayDay,
'bday_month' => $birthdayMonth,
'bday_year' => $birthdayYear,
'signature' => static::fixPostData( $row['signature'] )
);
/* Pseudo Fields */
$profileFields = array();
foreach( array( 'homepage', 'icq', 'aim', 'yahoo', 'location', 'interests', 'occupation', 'bio' ) AS $pseudo )
{
/* Are we retaining? */
if ( $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"] == 'no_convert' )
{
/* No, skip */
continue;
}
try
{
/* We don't actually need this, but we need to make sure the field was created */
$this->app->getLink( $pseudo, 'core_pfields_data' );
}
catch( \OutOfRangeException $e )
{
$libraryClass->convertProfileField( array(
'pf_id' => $pseudo,
'pf_name' => $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"],
'pf_desc' => '',
'pf_type' => 'Text',
'pf_content' => '[]',
'pf_member_hide' => 0,
'pf_max_input' => 255,
'pf_member_edit' => 1,
'pf_show_on_reg' => 0,
'pf_admin_only' => 0,
) );
}
$profileFields[ $pseudo ] = $row[ $pseudo ];
}
$libraryClass->convertMember( $info, $profileFields, $row['avatar'], rtrim( $this->app->_session['more_info']['convertMembers']['photo_location'], '/' ) );
$libraryClass->setLastKeyValue( $row['userid'] );
}
}
/**
@@ -28,7 +28,7 @@ class _Phpbb extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "phpBB 3.1";
return "phpBB (3.1.x/3.2.x)";
}
/**
@@ -98,6 +98,24 @@ class _Phpbb extends \IPS\convert\Software
);
}
/**
* Allows software to add additional menu row options
*
* @param array $rows Existing rows
* @return array
*/
public function extraMenuRows( $rows )
{
if( isset( $rows['convertBanfilters'] ) )
{
$rows['convertBanfilters2'] = $rows['convertBanfilters'];
$rows['convertBanfilters2']['step_method'] = 'convertBanfilters2';
$rows['convertBanfilters2']['source_rows'] = $this->countRows( static::canConvert()['convertBanfilters2']['table'], static::canConvert()['convertBanfilters2']['where'] );
}
return $rows;
}
/**
* Count Source Rows for a specific step
*
@@ -310,6 +328,9 @@ class _Phpbb extends \IPS\convert\Software
/* Content Counts */
\IPS\Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
/* Attachments */
\IPS\Task::queue( 'core', 'RebuildAttachmentThumbnails', array( 'app' => $this->app->app_id ), 1, array( 'app' ) );
/* First Post Data */
\IPS\Task::queue( 'convert', 'RebuildConversationFirstIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
@@ -698,8 +719,7 @@ class _Phpbb extends \IPS\convert\Software
{
$userfields = $this->db->select( '*', 'profile_fields_data', array( "user_id=?", $row['user_id'] ) )->first();
}
catch( \UnderflowException $e )
{}
catch( \UnderflowException $e ) {}
foreach( $this->db->select( '*', 'profile_fields' ) AS $field )
{
@@ -720,6 +740,10 @@ class _Phpbb extends \IPS\convert\Software
}
}
}
/* PM Folders */
$pmFolders = iterator_to_array( $this->db->select( 'folder_name', 'privmsgs_folder', array( 'user_id=?', $row['user_id'] ) ) );
$info['pconversation_filters'] = count( $pmFolders ) ? $pmFolders : NULL;
/* Finally */
$libraryClass->convertMember( $info, $pfields, $filename, $filepath );
@@ -946,7 +970,7 @@ class _Phpbb extends \IPS\convert\Software
$maps = array();
/* First one first initial author */
$maps[$row['author_id']] = array(
$maps[ $row['author_id'] ] = array(
'map_user_id' => $row['author_id'],
'map_is_starter' => 1,
'map_last_topic_reply' => $row['message_time'],
@@ -973,13 +997,18 @@ class _Phpbb extends \IPS\convert\Software
to a custom folder then they will have a row in privmsgs_to and we will end up resetting map_is_starter to 0 otherwise */
if( isset( $maps[ $to['user_id'] ] ) )
{
if( $to['folder_id'] > 0 )
{
$maps[ $to['user_id'] ]['map_folder_id'] = $this->_getPmFolder( $to['user_id'], $to['folder_id'] );
}
continue;
}
$maps[ $to['user_id'] ] = array(
'map_user_id' => $to['user_id'],
'map_is_starter' => 0,
'map_last_topic_reply' => $row['message_time']
'map_last_topic_reply' => $row['message_time'],
'map_folder_id' => ( $to['folder_id'] > 0 ) ? $this->_getPmFolder( $to['user_id'], $to['folder_id'] ) : FALSE
);
}
@@ -1045,4 +1074,108 @@ class _Phpbb extends \IPS\convert\Software
return NULL;
}
/**
* @brief Lookup cache
*/
protected static $pmFolders = array();
/**
* @brief PhpBB Source Folders
*/
protected static $phpBbFolders = NULL;
/**
* Get array key for the folder
*
* @param int $user User ID
* @param string $folderId Folder Name
* @return boolean
*/
protected function _getPmFolder( $user, $folderId )
{
/* Check for cached folder info */
if( isset( static::$pmFolders[ $user ][ $folderId ] ) )
{
return static::$pmFolders[ $user ][ $folderId ];
}
/* Check for cached phpBB data */
if( static::$phpBbFolders === NULL )
{
static::$phpBbFolders = iterator_to_array( $this->db->select( 'folder_id,folder_name', 'privmsgs_folder' )->setKeyField( 'folder_id' )->setValueField( 'folder_name' ) );
}
try
{
/* Does the referenced folder exist in PhpBB? */
if( !isset( static::$phpBbFolders[ $folderId ] ) )
{
throw new \OutOfRangeException;
}
$member = \IPS\Member::load( $this->app->getLink( (int) $user, 'core_members' ) );
$filters = json_decode( $member->pconversation_filters, TRUE );
/* No PM Folders or it's a guest */
if( $filters === NULL OR !$member->member_id )
{
throw new \OutOfRangeException;
}
}
catch( \OutOfRangeException $e )
{
return static::$pmFolders[ $user ][ $folderId ] = FALSE;
}
/* Search PM folders and return match */
return static::$pmFolders[ $user ][ $folderId ] = array_search( static::$phpBbFolders[ $folderId ], $filters );
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
$password = html_entity_decode( $password );
$success = FALSE;
$hash = $member->conv_password;
/* phpBB 3.1 */
if( preg_match( '/^\$2[ay]\$(0[4-9]|[1-2][0-9]|3[0-1])\$[a-zA-Z0-9.\/]{53}/', $hash ) )
{
require_once \IPS\ROOT_PATH . "/applications/convert/sources/Login/PasswordHash.php";
$ph = new \PasswordHash( 8, TRUE );
$success = $ph->CheckPassword( $password, $member->conv_password ) ? TRUE : FALSE;
}
$hashLibrary = new \IPS\convert\Login\HashCryptPrivate;
if ( $success === FALSE )
{
/* phpBB3 */
$single_md5_pass = md5( $password );
$itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
if ( \strlen( $hash ) == 34 )
{
$success = ( \IPS\Login::compareHashes( $hash, $hashLibrary->hashCryptPrivate( $password, $hash, $itoa64 ) ) ) ? TRUE : FALSE;
}
else
{
$success = ( \IPS\Login::compareHashes( $hash, $single_md5_pass ) ) ? TRUE : FALSE;
}
}
/* phpBB2 */
if ( !$success )
{
$success = ( \IPS\Login::compareHashes( $hash, $hashLibrary->hashCryptPrivate( $single_md5_pass, $hash, $itoa64 ) ) ) ? TRUE : FALSE ;
}
return $success;
}
}
@@ -28,7 +28,7 @@ class _Punbb extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "PunBB 1.x";
return "PunBB (1.x)";
}
/**
@@ -454,4 +454,35 @@ class _Punbb extends \IPS\convert\Software
return NULL;
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
$success = FALSE;
if ( mb_strlen( $member->conv_password ) == 40 )
{
/* Password with salt */
$success = \IPS\Login::compareHashes( $member->conv_password, sha1( $member->conv_password_extra . sha1( $password ) ) );
if ( !$success )
{
/* No salt */
$success = \IPS\Login::compareHashes( $member->conv_password, sha1( $password ) );
}
}
else
{
/* MD5 */
$success = \IPS\Login::compareHashes( $member->conv_password, md5( $password ) );
}
return $success;
}
}
@@ -28,7 +28,7 @@ class _Smf extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "Simple Machines Forum";
return "Simple Machines Forum (2.0.x)";
}
/**
@@ -226,7 +226,7 @@ class _Smf extends \IPS\convert\Software
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => 'user_name',
'field_required' => TRUE,
'field_extra' => array( 'options' => array( 'user_name', 'display_name' ) ),
'field_extra' => array( 'options' => array( 'user_name' => 'user_name', 'display_name' => 'display_name' ) ),
'field_hint' => NULL,
);
@@ -298,7 +298,7 @@ class _Smf extends \IPS\convert\Software
\IPS\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 ), 4, array( 'app' ) );
\IPS\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" );
}
@@ -318,7 +318,7 @@ class _Smf extends \IPS\convert\Software
$post = str_replace( $search, $replace, $post );
// And img tags
$post = preg_replace("#\[img width=(\d+)(?: height=(\d+))?\]([a-zA-Z0-9.:\-/%\?&_]+)\[\/img\]#i", "[img]$3[/img]", $post);
$post = preg_replace("#\[img width=(\d+)(?: height=(\d+))?\]([a-zA-Z0-9.:\-/%\?&_=~\#\(\);:]+)\[\/img\]#i", "[img]$3[/img]", $post);
//Quotes
$post = preg_replace("#\[quote author=(.+?) link=(.+?)=(\d+)\.msg(\d+)(.+?)date=(\d+)\](.+)\[\/quote\]#i", "[quote name=\"$1\" post=\"$4\" timestamp=\"$6\"]$7[/quote]", $post);
@@ -648,7 +648,7 @@ class _Smf extends \IPS\convert\Software
'email' => $row['email_address'],
'name' => $name,
'password' => $row['passwd'],
'password_extra' => $row['password_salt'],
'password_extra' => $row['member_name'], // We need to keep the original member name for the SMF password hash
'member_group_id' => $row['id_group'],
'joined' => $row['date_registered'],
'ip_address' => $row['member_ip'],
@@ -900,4 +900,45 @@ class _Smf extends \IPS\convert\Software
return NULL;
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
if ( \IPS\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 ) ) )
{
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 ) ) )
{
return TRUE;
}
else
{
require_once \IPS\ROOT_PATH . "/applications/convert/sources/Login/PasswordHash.php";
$ph = new \PasswordHash( 8, TRUE );
if( $ph->CheckPassword( mb_strtolower( $member->name ) . $password, $member->conv_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 ( $ph->CheckPassword( mb_strtolower( $member->conv_password_extra ) . $password, $member->conv_password ) )
{
return TRUE;
}
}
return FALSE;
}
}
@@ -132,6 +132,32 @@ class _UBBthreads extends \IPS\convert\Software
),
);
}
/**
* Allows software to add additional menu row options
*
* @param array $rows Existing rows
* @return array
*/
public function extraMenuRows( $rows )
{
$count = $this->countRows( static::canConvert()['convertMembersFollowers']['table'], static::canConvert()['convertMembersFollowers']['where'] );
if( $count )
{
$rows['convertMembersFollowers'] = array(
'step_method' => 'convertMembersFollowers',
'step_title' => 'convert_follows',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_follow', array( 'follow_app=? and follow_area=?', 'core', 'member' ) )->first(),
'source_rows' => $count,
'per_cycle' => 500,
'dependencies' => array( 'convertMembers' ),
'link_type' => 'core_follow',
);
}
return $rows;
}
/**
* Can we convert passwords from this software.
@@ -265,6 +291,15 @@ class _UBBthreads extends \IPS\convert\Software
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack( 'username_hint' ),
);
$return['convertMembers']['photo_location'] = array(
'field_class' => 'IPS\\Helpers\\Form\\Text',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack('convert_ubbthreads_photo_path'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
);
foreach( array( 'homepage', 'occupation', 'hobbies', 'location', 'icq', 'yahoo', 'aim', 'msn' ) AS $field )
{
\IPS\Member::loggedIn()->language()->words["field_{$field}"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field', FALSE, array( 'sprintf' => $field ) );
@@ -315,7 +350,7 @@ class _UBBthreads extends \IPS\convert\Software
\IPS\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 ), 4, array( 'app' ) );
\IPS\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" );
}
@@ -584,8 +619,16 @@ class _UBBthreads extends \IPS\convert\Software
/* Profile photo */
$profilePhotoName = NULL;
$profilePhotoData = NULL;
$profilePhotoPath = NULL;
if ( !empty( $row['USER_AVATAR'] ) AND ( $row['USER_AVATAR'] != 'http://' ) )
/* Is it a file? */
if( !empty( $row['USER_AVATAR'] ) AND mb_substr( $row['USER_AVATAR'], 0, 1 ) == '/' )
{
$profilePhotoPath = pathinfo( rtrim( $this->app->_session['more_info']['convertMembers']['photo_location'], '/' ) . $row['USER_AVATAR'], PATHINFO_DIRNAME );
$profilePhotoName = pathinfo( rtrim( $this->app->_session['more_info']['convertMembers']['photo_location'], '/' ) . $row['USER_AVATAR'], PATHINFO_BASENAME );
}
/* Or an URL? */
elseif ( !empty( $row['USER_AVATAR'] ) AND ( $row['USER_AVATAR'] != 'http://' ) AND mb_substr( $row['USER_AVATAR'], 0, 4 ) )
{
try
{
@@ -595,7 +638,7 @@ class _UBBthreads extends \IPS\convert\Software
catch( \IPS\Http\Request\Exception $e ) { }
}
$libraryClass->convertMember( $info, $pfields, $profilePhotoName, NULL, $profilePhotoData );
$libraryClass->convertMember( $info, $pfields, $profilePhotoName, $profilePhotoPath, $profilePhotoData );
$libraryClass->setLastKeyValue( $row['USER_ID'] );
}
}
@@ -609,7 +652,7 @@ class _UBBthreads extends \IPS\convert\Software
{
$libraryClass = $this->getLibrary();
foreach ( $this->fetch( 'WATCH_LISTS', 'WATCH_ID', array( 'WATCH_TYPE=?', 'u' ), 'USER_ID ASC, WATCH_ID ASC' ) as $row )
foreach ( $this->fetch( 'WATCH_LISTS', 'WATCH_ID', array( 'WATCH_TYPE=?', 'u' ) ) as $row )
{
$libraryClass->convertFollow( array(
'follow_app' => 'core',
@@ -769,7 +812,7 @@ class _UBBthreads extends \IPS\convert\Software
$data = $this->app->getLink( (int) $matches[1], array( 'members', 'core_members' ) );
$item = \IPS\Member::load( $data );
if( $item->canView() )
if( \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members' ) ) )
{
return $item->url();
}
@@ -782,4 +825,37 @@ class _UBBthreads extends \IPS\convert\Software
return NULL;
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
$hash = $member->members_pass_hash;
$salt = $member->members_pass_salt;
if ( \IPS\Login::compareHashes( $hash, md5( $password ) ) )
{
return TRUE;
}
// Not using md5, UBB salts the password with the password
// IPB already md5'd it though, *sigh*
if ( \IPS\Login::compareHashes( $hash, md5( md5( $salt ) . crypt( $password, $password ) ) ) )
{
return TRUE;
}
// Now standard IPB check.
if ( \IPS\Login::compareHashes( $hash, md5( md5( $salt ) . md5( $password ) ) ) )
{
return TRUE;
}
return FALSE;
}
}
@@ -27,7 +27,7 @@ class _Vanilla extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "Vanilla 2";
return "Vanilla 2 (2.2.x/2.3.x)";
}
/**
@@ -118,8 +118,8 @@ class _Vanilla extends \IPS\convert\Software
* Resolve the filesystem location of a file from a path stored in the database
* There are several different ways Vanilla may store these, including as remote URL's
*
* @param $location File location retrieved from the database
* @param $uploadsPath Configured uploads path
* @param string $location File location retrieved from the database
* @param string $uploadsPath Configured uploads path
* @return \IPS\Http\Url|string|void
*/
public static function parseMediaLocation( $location, $uploadsPath )
@@ -325,7 +325,7 @@ class _Vanilla extends \IPS\convert\Software
\IPS\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 ), 4, array( 'app' ) );
\IPS\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" );
}
@@ -566,4 +566,31 @@ class _Vanilla extends \IPS\convert\Software
$libraryClass->setLastKeyValue( $row['MessageID'] );
}
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
/* Vanilla 2.2 */
if( preg_match( '/^\$2[ay]\$(0[4-9]|[1-2][0-9]|3[0-1])\$[a-zA-Z0-9.\/]{53}/', $member->conv_password ) OR mb_substr( $member->conv_password, 0, 3 ) == '$P$' )
{
require_once \IPS\ROOT_PATH . "/applications/convert/sources/Login/PasswordHash.php";
$ph = new \PasswordHash( 8, TRUE );
return $ph->CheckPassword( $password, $member->conv_password ) ? TRUE : FALSE;
}
if ( \IPS\Login::compareHashes( $member->conv_password, md5( md5( str_replace( '&#39;', "'", html_entity_decode( $password ) ) ) . $member->misc ) ) )
{
return TRUE;
}
else
{
return FALSE;
}
}
}
@@ -166,6 +166,43 @@ class _Vbulletin extends \IPS\convert\Software
)
);
}
/**
* 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 'userchangelog':
return $this->db->select( 'count(changeid)', 'userchangelog', array( $this->db->in( 'fieldname', array_keys( static::$changeLogTypes ) ) ) )->first();
break;
case 'pm':
/* vB doesn't put an index on a column that makes this converison much quicker, so we'll do it. */
if( !$this->db->checkForIndex( 'pm', 'parent_id' ) )
{
$this->db->addIndex( 'pm', array(
'type' => 'key',
'name' => 'parent_id',
'columns' => array( 'parentpmid', 'folderid' )
) );
}
return parent::countRows( $table, $where, $recache );
break;
default:
return parent::countRows( $table, $where, $recache );
break;
}
}
/**
* Can we convert passwords from this software.
@@ -479,12 +516,15 @@ class _Vbulletin extends \IPS\convert\Software
/* Content Counts */
\IPS\Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
/* Clubs */
\IPS\Task::queue( 'convert', 'RecountClubMembers', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
/* First Post Data */
\IPS\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 ), 4, array( 'app' ) );
\IPS\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_announce_rebuild" );
}
@@ -882,7 +922,7 @@ class _Vbulletin extends \IPS\convert\Software
/**
* @brief Member history type map
*/
protected $changeLogTypes = array( 'username' => 'display_name', 'email' => 'email_change', 'usergroupid' => 'member_group_id', 'membergroupids' => 'mgroup_others' );
protected static $changeLogTypes = array( 'username' => 'display_name', 'email' => 'email_change', 'usergroupid' => 'member_group_id', 'membergroupids' => 'mgroup_others' );
/**
* Convert member history
@@ -892,50 +932,15 @@ class _Vbulletin extends \IPS\convert\Software
public function convertMemberHistory()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'changeid' );
$fixGroups = function( $string )
foreach( $this->fetch( 'userchangelog', 'changeid', array( $this->db->in( 'fieldname', array_keys( static::$changeLogTypes ) ) ) ) AS $change )
{
$groups = explode( ',', $string );
$newGroups = array();
array_walk( $groups, function( &$item, $key ) use ( &$newGroups )
{
try
{
$item = $this->app->getLink( $item, 'core_groups' );
$newGroups[] = $item;
}
catch( \OutOfRangeException $e ){}
});
return implode( ',', $newGroups );
};
foreach( $this->fetch( 'userchangelog', 'changeid' ) AS $change )
{
if( !in_array( $change['fieldname'], array_keys( $this->changeLogTypes ) ) )
{
$libraryClass->setLastKeyValue( $change['changeid'] );
continue;
}
/* Any processing we need to do */
switch( $this->changeLogTypes[ $change['fieldname'] ] )
{
case 'member_group_id':
case 'mgroup_others':
$change['oldvalue'] = $fixGroups( $change['oldvalue'] );
$change['newvalue'] = $fixGroups( $change['newvalue'] );
break;
}
$libraryClass->convertMemberHistory( array(
'log_id' => $change['changeid'],
'log_member' => $change['userid'],
'log_by' => $change['adminid'],
'log_type' => $this->changeLogTypes[ $change['fieldname'] ],
'log_type' => static::$changeLogTypes[ $change['fieldname'] ],
'log_data' => array( 'old' => $change['oldvalue'], 'new' => $change['newvalue'] ),
'log_date' => $change['change_time']
)
@@ -1241,7 +1246,7 @@ class _Vbulletin extends \IPS\convert\Software
}
}
$libraryClass->convertMember( $info, $profileFields, $filename, $filepath, $filedata );
$libraryClass->convertMember( $info, $profileFields, $filename, $filepath );
/* Any friends need converting to followers? */
foreach( $this->db->select( '*', 'userlist', array( "type=? AND friend=? AND userid=?", 'buddy', 'yes', $user['userid'] ) ) AS $follower )
@@ -1933,10 +1938,11 @@ class _Vbulletin extends \IPS\convert\Software
}
/* Profile URLs can be in one of 3 formats really...
* /member.php/1-name
* /members/1-name
* /member.php?u=1
*/
* /member.php/1-name
* /members/1-name
* /member.php?u=1
* /member.php?1-name
*/
$path = $url->data[ \IPS\Http\Url::COMPONENT_PATH ];
if( mb_strpos( $path, 'member.php' ) !== FALSE )
{
@@ -1944,6 +1950,10 @@ class _Vbulletin extends \IPS\convert\Software
{
$oldId = \IPS\Request::i()->u;
}
elseif( preg_match( '#^(\d+)-[^/]+#i', $url->data[ \IPS\Http\Url::COMPONENT_QUERY ], $matches ) )
{
$oldId = $matches[1];
}
else
{
$queryStringPieces = explode( '-', mb_substr( $path, mb_strpos( $path, 'member.php/' ) + mb_strlen( 'member.php/' ) ) );
@@ -1971,4 +1981,23 @@ class _Vbulletin extends \IPS\convert\Software
return NULL;
}
/**
* Process a login
*
* @param \IPS\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, md5( md5( str_replace( '&#39;', "'", html_entity_decode( $password ) ) ) . $member->conv_password_extra ) ) )
{
return TRUE;
}
else
{
return FALSE;
}
}
}
@@ -158,6 +158,10 @@ class _Vbulletin5 extends \IPS\convert\Software
$where = array( $this->db->in( 'nodeid', $clubs ) );
return parent::countRows( $table, $where, $recache );
break;
case 'userchangelog':
return $this->db->select( 'count(changeid)', 'userchangelog', array( $this->db->in( 'fieldname', array_keys( static::$changeLogTypes ) ) ) )->first();
break;
default:
return parent::countRows( $table, $where, $recache );
@@ -464,8 +468,14 @@ class _Vbulletin5 extends \IPS\convert\Software
/* Content Counts */
\IPS\Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
/* Clubs */
\IPS\Task::queue( 'convert', 'RecountClubMembers', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
/* First Post Data */
\IPS\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' ) );
return array( "f_search_index_rebuild", "f_clear_caches", "f_rebuild_pms", "f_signatures_rebuild" );
}
@@ -488,6 +498,77 @@ class _Vbulletin5 extends \IPS\convert\Software
/* Remove video tags and allow our parser to handle the embeds it supports */
$post = preg_replace( "#\[video=[a-z]+;[a-z0-9_]+\](.*?)\[\/video\]#i", '$1', $post );
/* IMG2 BBcode */
$matches = array();
preg_match_all( "/\[IMG2=JSON](.+?)\[\/IMG2\]/i", $post, $matches );
if ( count( $matches ) )
{
foreach( $matches[0] as $k => $v )
{
try
{
/* Make sure the JSON value exists */
if( !isset( $matches[1][ $k ] ) )
{
throw new \DomainException;
}
$decoded = json_decode( $matches[1][ $k ], TRUE );
/* Make sure the JSON is valid and contains src */
if( !isset( $decoded['src'] ) OR empty( $decoded['src'] ) )
{
throw new \DomainException;
}
$post = str_replace( $v, "[img]{$decoded['src']}[/img]", $post );
}
catch( \DomainException $e )
{
continue;
}
}
}
/* Mentions */
$matches = array();
preg_match_all( '#\[user(=\"?(\d+)\"?)?\](.+?)\[\/user\]#i', $post, $matches ); // this purposefully matches more than the default vB mention.
if ( count( $matches ) )
{
if ( isset( $matches[1] ) )
{
$mentions = array();
foreach( $matches[1] AS $k => $v )
{
if ( isset( $matches[3][$k] ) )
{
$name = trim( $matches[3][ $k ], '@' );
$mentions[ $name ] = $v;
}
}
$maps = array();
$urls = array();
$cardUrls = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_members', array( \IPS\Db::i()->in( 'name', array_keys( $mentions ) ) ) ), 'IPS\Member' ) AS $member )
{
$maps[ $member->name ] = $member->member_id;
$urls[ $member->name ] = $member->url();
$cardUrls[ $member->name ] = $member->url()->setQueryString( 'do', 'hovercard' );
}
foreach( $mentions AS $member_name => $member_id )
{
$maps[ $member_name ] = preg_quote( $maps[ $member_name ], '#' );
$memberNameEscaped = preg_quote( $member_name, '#' );
$post = preg_replace( "#\[user(=\"?(\d+)\"?)?\]@?{$memberNameEscaped}\[\/user\]#i", "<a contenteditable=\"false\" rel=\"\" href=\"{$urls[ $member_name ]}\" data-mentionid=\"{$maps[ $member_name ]}\" data-ipshover-target=\"{$cardUrls[ $member_name ]}\" data-ipshover=\"\">@{$member_name}</a>", $post );
}
}
}
return $post;
}
@@ -822,7 +903,7 @@ class _Vbulletin5 extends \IPS\convert\Software
/**
* @brief Member history type map
*/
protected $changeLogTypes = array( 'username' => 'display_name', 'email' => 'email_change', 'usergroupid' => 'member_group_id', 'membergroupids' => 'mgroup_others' );
protected static $changeLogTypes = array( 'username' => 'display_name', 'email' => 'email_change', 'usergroupid' => 'member_group_id', 'membergroupids' => 'mgroup_others' );
/**
* Convert member history
@@ -832,53 +913,18 @@ class _Vbulletin5 extends \IPS\convert\Software
public function convertMemberHistory()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'changeid' );
$fixGroups = function( $string )
foreach( $this->fetch( 'userchangelog', 'changeid', array( $this->db->in( 'fieldname', array_keys( static::$changeLogTypes ) ) ) ) AS $change )
{
$groups = explode( ',', $string );
$newGroups = array();
array_walk( $groups, function( &$item, $key ) use ( &$newGroups )
{
try
{
$item = $this->app->getLink( $item, 'core_groups' );
$newGroups[] = $item;
}
catch( \OutOfRangeException $e ){}
});
return implode( ',', $newGroups );
};
foreach( $this->fetch( 'userchangelog', 'changeid' ) AS $change )
{
if( !in_array( $change['fieldname'], array_keys( $this->changeLogTypes ) ) )
{
$libraryClass->setLastKeyValue( $change['changeid'] );
continue;
}
/* Any processing we need to do */
switch( $this->changeLogTypes[ $change['fieldname'] ] )
{
case 'member_group_id':
case 'mgroup_others':
$change['oldvalue'] = $fixGroups( $change['oldvalue'] );
$change['newvalue'] = $fixGroups( $change['newvalue'] );
break;
}
$libraryClass->convertMemberHistory( array(
'log_id' => $change['changeid'],
'log_member' => $change['userid'],
'log_by' => $change['adminid'],
'log_type' => $this->changeLogTypes[ $change['fieldname'] ],
'log_type' => static::$changeLogTypes[ $change['fieldname'] ],
'log_data' => array( 'old' => $change['oldvalue'], 'new' => $change['newvalue'] ),
'log_date' => $change['change_time'],
'log_ip_address' => long2ip( $change['ipaddress'] )
'log_ip_address' => long2ip( (int) $change['ipaddress'] )
)
);
@@ -1221,7 +1267,7 @@ class _Vbulletin5 extends \IPS\convert\Software
$libraryClass->convertMemberHistory( array(
'log_id' => 'w' . $warn['nodeid'],
'log_member' => $warn['infracteduserid'],
'log_by' => $warn['userid'],
'log_by' => $warn['actionuserid'],
'log_type' => 'warning',
'log_data' => array( 'wid' => $warnId ),
'log_date' => $warn['actiondateline']
@@ -1344,18 +1390,19 @@ class _Vbulletin5 extends \IPS\convert\Software
'map_user_active' => 1,
'map_user_banned' => 0,
'map_has_unread' => 0,
'map_is_starter' => ( $pm['userid'] == $pm['userid'] ) ? 1 : 0,
'map_is_starter' => 1,
);
foreach( $this->db->select( '*', 'node', array( "parentid=?", $pm['nodeid'] ) ) AS $post )
/* All other maps */
foreach( $this->db->select( '*', 'sentto', array( "nodeid=? AND userid!=?", $pm['nodeid'], $pm['userid'] ) ) AS $map )
{
$maps[ $post['userid'] ] = array(
'map_user_id' => $post['userid'],
$maps[ $map['userid'] ] = array(
'map_user_id' => $map['userid'],
'map_topic_id' => $pm['nodeid'],
'map_user_active' => 1,
'map_user_active' => !$map['deleted'],
'map_user_banned' => 0,
'map_has_unread' => 0,
'map_is_starter' => ( $post['userid'] == $pm['userid'] ) ? 1 : 0,
'map_has_unread' => !$map['msgread'],
'map_is_starter' => 0
);
}
@@ -1880,4 +1927,42 @@ class _Vbulletin5 extends \IPS\convert\Software
return NULL;
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public static function login( $member, $password )
{
/* If no algorithm is defined, use the legacy handler */
if ( \strpos( $member->misc, 'blowfish' ) === FALSE and \strpos( $member->misc, 'legacy' ) === FALSE )
{
return \IPS\convert\Software\Core\Vbulletin::login( $member, $password );
}
/* Which do we need to use? */
$algo = explode( ':', $member->misc );
switch( $algo[ 0 ] )
{
case 'blowfish':
/* vBulletin uses PasswordHash, however they md5 once the password prior to checking */
$md5_once_password = md5( $password );
require_once \IPS\ROOT_PATH . "/applications/convert/sources/Login/PasswordHash.php";
$ph = new \PasswordHash( $algo[ 1 ], FALSE );
return $ph->CheckPassword( $md5_once_password, $member->conv_password );
break;
case 'legacy':
/* Legacy Passwords are stored in a format of HASH SALT so we need to explode on the space. */
$token = explode( ' ', $member->conv_password );
$member->conv_password = $token[0];
$member->conv_password_extra = $token[1];
return \IPS\convert\Software\Core\Vbulletin::login( $member, $password );
break;
}
}
}
@@ -231,4 +231,34 @@ class _Wordpress extends \IPS\convert\Software
return array( "f_search_index_rebuild", "f_clear_caches" );
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
$success = FALSE;
// If the hash is still md5...
if ( \strlen( $member->conv_password ) <= 32 )
{
$success = ( \IPS\Login::compareHashes( $member->conv_password, md5( $password ) ) ) ? TRUE : FALSE;
}
// New pass hash check
else
{
// Init the pass class
require_once \IPS\ROOT_PATH . "/applications/convert/sources/Login/PasswordHash.php";
$ph = new \PasswordHash( 8, TRUE );
// Check it
$success = $ph->CheckPassword( $password, $member->conv_password ) ? TRUE : FALSE;
}
return $success;
}
}
@@ -1,7 +1,7 @@
<?php
/**
* @brief Converter XenForo 1.x Master Class
* @brief Converter XenForo 1.x/2.x Master Class
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
@@ -20,6 +20,48 @@ 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;
/**
* 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::$isLegacy = FALSE;
}
}
}
catch( \Exception $e ) {} # If we can't query, we won't be able to do anything anyway
}
return $return;
}
/**
* Software Name
*
@@ -27,7 +69,7 @@ class _Xenforo extends \IPS\convert\Software
*/
public static function softwareName()
{
return "XenForo (1.x)";
return "XenForo (1.5.x/2.0.x)";
}
/**
@@ -85,10 +127,10 @@ class _Xenforo extends \IPS\convert\Software
'where' => NULL
),
'convertMemberHistory' => array(
'table' => 'xf_user_change_log',
'table' => ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) ) ? 'xf_change_log' : 'xf_user_change_log',
'where' => NULL
),
'convertWarnReason' => array(
'convertWarnReasons' => array(
'table' => 'xf_warning_definition',
'where' => NULL
),
@@ -123,6 +165,34 @@ class _Xenforo extends \IPS\convert\Software
);
}
/**
* 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 )
{
/* XF1 */
case 'xf_user_change_log':
return $this->db->select( 'count(log_id)', 'xf_user_change_log', array( $this->db->in( 'field', array_keys( static::$changeLogTypes ) ) ) )->first();
break;
/* XF2 */
case 'xf_change_log':
return $this->db->select( 'count(log_id)', 'xf_change_log', array( 'content_type=? AND ' . $this->db->in( 'field', array_keys( static::$changeLogTypes ) ), 'user' ) )->first();
break;
default:
return parent::countRows( $table, $where, $recache );
break;
}
}
/**
* Can we convert passwords from this software.
*
@@ -218,7 +288,7 @@ class _Xenforo extends \IPS\convert\Software
foreach( $this->db->select( '*', 'xf_user_field' ) AS $field )
{
\IPS\Member::loggedIn()->language()->words["map_pfield_{$field['field_id']}"] = $this->getPhrase( "user_field_{$field['field_id']}" );
\IPS\Member::loggedIn()->language()->words["map_pfield_{$field['field_id']}"] = $this->getPhrase( "user_field_{$field['field_id']}", "user_field_title.{$field['field_id']}" );
\IPS\Member::loggedIn()->language()->words["map_pfield_{$field['field_id']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_pfield_desc' );
$return['convertProfileFields']["map_pfield_{$field['field_id']}"] = array(
@@ -324,7 +394,7 @@ class _Xenforo extends \IPS\convert\Software
continue;
}
$title = $this->getPhrase( 'option_' . $setting );
$title = $this->getPhrase( 'option_' . $setting, 'option.' . $setting );
if ( !$title )
{
@@ -340,13 +410,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 )
@@ -379,6 +451,9 @@ class _Xenforo extends \IPS\convert\Software
/* First Post Data */
\IPS\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' ) );
/* Rebuild Leaderboard */
\IPS\Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
\IPS\Db::i()->delete('core_reputation_leaderboard_history');
@@ -395,7 +470,7 @@ class _Xenforo extends \IPS\convert\Software
public static function fixPostData( $post )
{
// run everything through htmlspecialchars to prevent XSS
$post = htmlspecialchars( $post, \IPS\HTMLENTITIES | ENT_QUOTES, 'UTF-8', FALSE );
$post = htmlspecialchars( $post, ENT_DISALLOWED | ENT_QUOTES, 'UTF-8', FALSE );
// find YouTube ID's and replace.
$post = preg_replace( '#\[media=youtube\](.+?)\[/media\]#i', '[media]http://www.youtube.com/watch?v=$1[/media]', $post );
@@ -410,9 +485,9 @@ class _Xenforo extends \IPS\convert\Software
$mentions = array();
foreach( $matches[1] AS $k => $v )
{
if ( isset( $matches[2][$k] ) )
if ( isset( $matches[2][ $k ] ) )
{
$name = trim( $matches[2][$k], '@' );
$name = trim( $matches[2][ $k ], '@' );
$mentions[$name] = $v;
}
}
@@ -422,17 +497,17 @@ class _Xenforo extends \IPS\convert\Software
$cardUrls = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_members', array( \IPS\Db::i()->in( 'name', array_keys( $mentions ) ) ) ), 'IPS\Member' ) AS $member )
{
$maps[$member->name] = $member->member_id;
$urls[$member->name] = $member->url();
$cardUrls[$member->name] = $member->url()->setQueryString( 'do', 'hovercard' );
$maps[ $member->name ] = $member->member_id;
$urls[ $member->name ] = $member->url();
$cardUrls[ $member->name ] = $member->url()->setQueryString( 'do', 'hovercard' );
}
foreach( $mentions AS $member_name => $member_id )
{
$maps[$member_name] = preg_quote( $maps[$member_name], '#' );
$member_name = preg_quote( $member_name, '#' );
$maps[ $member_name ] = preg_quote( $maps[ $member_name ], '#' );
$memberNameEscaped = preg_quote( $member_name, '#' );
$post = preg_replace( "#\[user={$member_id}\]@?{$member_name}\[\/user\]#i", "<a contenteditable=\"false\" rel=\"\" href=\"{$urls[$member_name]}\" data-mentionid=\"{$maps[$member_name]}\" data-ipshover-target=\"{$cardUrls[$member_name]}\" data-ipshover=\"\">@{$member_name}</a>", $post );
$post = preg_replace( "#\[user={$member_id}\]@?{$memberNameEscaped}\[\/user\]#i", "<a contenteditable=\"false\" rel=\"\" href=\"{$urls[ $member_name ]}\" data-mentionid=\"{$maps[ $member_name ]}\" data-ipshover-target=\"{$cardUrls[ $member_name ]}\" data-ipshover=\"\">@{$member_name}</a>", $post );
}
}
}
@@ -530,18 +605,52 @@ class _Xenforo extends \IPS\convert\Software
/* We need to figure out where our file lives - if it's remote, then we need to use file_get_contents() and pass the raw data. */
$filepath = NULL;
$filedata = NULL;
if ( mb_substr( $row['image_url'], 0, 4 ) == 'http' )
$filepathx2 = NULL;
$filedatax2 = NULL;
$filenamex2 = NULL;
/* Sprites */
if( $row['sprite_mode'] )
{
$images = $this->_emoticonsFromSprite( rtrim( $this->app->_session['more_info']['convertEmoticons']['emoticon_path'], '/' ) . '/' . $row['image_url'], \unserialize( $row['sprite_params'] ) );
$filedata = $images['emoticon'];
if( isset( $images['emoticon_x2'] ) )
{
$filedatax2 = $images['emoticon_x2'];
/* We always save the sprites to PNG */
$filenamex2 = "{$row['title']}.png";
}
/* We always save the sprites to PNG */
$filename = "{$row['title']}.png";
}
elseif ( mb_substr( $row['image_url'], 0, 4 ) == 'http' )
{
$filedata = file_get_contents( $row['image_url'] );
$fileurl = explode( '/', $row['image_url'] );
$filename = array_pop( $fileurl );
if( static::$isLegacy == FALSE AND !empty( $row['image_url_2x'] ) )
{
$filedata = file_get_contents( $row['image_url_2x'] );
$fileurlx2 = explode( '/', $row['image_url_2x'] );
$filenamex2 = array_pop( $fileurlx2 );
}
}
else
{
$fileurl = explode( '/', $row['image_url'] );
$filename = array_pop( $fileurl );
$filepath = rtrim( $this->app->_session['more_info']['convertEmoticons']['emoticon_path'], '/' ) . '/' . implode( '/', $fileurl );
if( static::$isLegacy == FALSE AND !empty( $row['image_url_2x'] ) )
{
$fileurlx2 = explode( '/', $row['image_url_2x'] );
$filenamex2 = array_pop( $fileurlx2 );
$filepathx2 = rtrim( $this->app->_session['more_info']['convertEmoticons']['emoticon_path'], '/' ) . '/' . implode( '/', $fileurlx2 );
}
}
/* XenForo allows multiple codes - we don't. */
@@ -552,7 +661,7 @@ class _Xenforo extends \IPS\convert\Software
try
{
$category = $this->db->select( '*', 'xf_smilie_category', array( "smilie_category_id=?", $row['smilie_category_id'] ) )->first();
$title = $this->getPhrase( "smilie_category_{$category['smilie_category_id']}_title" );
$title = $this->getPhrase( "smilie_category_{$category['smilie_category_id']}_title", "smilie_category_title.{$category['smilie_category_id']}" );
if ( is_null( $title ) )
{
@@ -579,10 +688,11 @@ class _Xenforo extends \IPS\convert\Software
'id' => $row['smilie_id'],
'typed' => $code,
'filename' => $filename,
'filenamex2' => $filenamex2,
'emo_position' => $row['display_order'],
);
$libraryClass->convertEmoticon( $info, $set, $this->app->_session['more_info']['convertEmoticons']['keep_existing_emoticons'], $filepath, $filedata );
$libraryClass->convertEmoticon( $info, $set, $this->app->_session['more_info']['convertEmoticons']['keep_existing_emoticons'], $filepath, $filedata, $filepathx2, $filedatax2 );
$libraryClass->setLastKeyValue( $row['smilie_id'] );
}
@@ -603,8 +713,8 @@ class _Xenforo extends \IPS\convert\Software
$info['pf_id'] = $row['field_id'];
$merge = $this->app->_session['more_info']['convertProfileFields']["map_pfield_{$row['field_id']}"] != 'none' ? $this->app->_session['more_info']['convertProfileFields']["map_pfield_{$row['field_id']}"] : NULL;
$info['pf_type'] = $this->_fieldMap( $row['field_type'] );
$info['pf_name'] = $this->getPhrase( "user_field_{$row['field_id']}" );
$info['pf_desc'] = $this->getPhrase( "user_field_{$row['field_id']}_desc" );
$info['pf_name'] = $this->getPhrase( "user_field_{$row['field_id']}", "user_field_title.{$row['field_id']}" );
$info['pf_desc'] = $this->getPhrase( "user_field_{$row['field_id']}_desc", "user_field_desc.{$row['field_id']}" );
$info['pf_content'] = ( !in_array( $row['field_type'], array( 'textbox', 'textarea' ) ) ) ? \unserialize( $row['field_choices'] ) : NULL;
$info['pf_not_null'] = $row['required'];
$info['pf_member_hide'] = ( $row['viewable_profile'] > 0 ) ? 0 : 1;
@@ -734,7 +844,7 @@ class _Xenforo extends \IPS\convert\Software
*
* @return void
*/
public function convertWarnReason()
public function convertWarnReasons()
{
$libraryClass = $this->getLibrary();
@@ -742,7 +852,7 @@ class _Xenforo extends \IPS\convert\Software
foreach( $this->fetch( 'xf_warning_definition', 'warning_definition_id' ) AS $row )
{
$title = $this->getPhrase( "warning_definition_{$row['warning_definition_id']}_title" );
$title = $this->getPhrase( "warning_definition_{$row['warning_definition_id']}_title", "warning_title.{$row['warning_definition_id']}" );
$remove = ( $row['expiry_type'] == 'never' ) ? 0 : $row['expiry_default'];
switch( $row['expiry_type'] )
@@ -777,7 +887,7 @@ class _Xenforo extends \IPS\convert\Software
/**
* @brief Member history type map
*/
protected $changeLogTypes = array( 'username' => 'display_name', 'email' => 'email_change', 'user_group_id' => 'member_group_id', 'secondar_group_ids' => 'mgroup_others' );
protected static $changeLogTypes = array( 'username' => 'display_name', 'email' => 'email_change', 'user_group_id' => 'member_group_id', 'secondary_group_ids' => 'mgroup_others' );
/**
* Convert member history
@@ -790,47 +900,27 @@ class _Xenforo extends \IPS\convert\Software
$libraryClass::setKey( 'log_id' );
$fixGroups = function( $string )
$userField = 'user_id';
$table = 'xf_user_change_log';
if( ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) ) )
{
$groups = explode( ',', $string );
$newGroups = array();
array_walk( $groups, function( &$item, $key ) use ( &$newGroups )
{
try
{
$item = $this->app->getLink( $item, 'core_groups' );
$newGroups[] = $item;
}
catch( \OutOfRangeException $e ){}
});
return implode( ',', $newGroups );
};
foreach( $this->fetch( 'xf_user_change_log', 'log_id' ) AS $change )
$table = 'xf_change_log';
$userField = 'content_id';
$where = array( 'content_type=? AND ' . $this->db->in( 'field', array_keys( static::$changeLogTypes ) ), 'user' );
}
else
{
if( !in_array( $change['field'], array_keys( $this->changeLogTypes ) ) )
{
$libraryClass->setLastKeyValue( $change['log_id'] );
continue;
}
/* Any processing we need to do */
switch( $this->changeLogTypes[ $change['field'] ] )
{
case 'member_group_id':
case 'mgroup_others':
$change['old_value'] = $fixGroups( $change['old_value'] );
$change['new_value'] = $fixGroups( $change['new_value'] );
break;
}
$where = array( $this->db->in( 'field', array_keys( static::$changeLogTypes ) ) );
}
foreach( $this->fetch( $table, 'log_id', $where ) AS $change )
{
$libraryClass->convertMemberHistory( array(
'log_id' => $change['log_id'],
'log_member' => $change['user_id'],
'log_by' => ( $change['edit_user_id'] !== $change['user_id'] ) ? $change['edit_user_id'] : null,
'log_type' => $this->changeLogTypes[ $change['field'] ],
'log_member' => $change[ $userField ],
'log_by' => ( $change['edit_user_id'] !== $change[ $userField ] ) ? $change['edit_user_id'] : null,
'log_type' => static::$changeLogTypes[ $change['field'] ],
'log_data' => array( 'old' => $change['old_value'], 'new' => $change['new_value'] ),
'log_date' => $change['edit_date']
)
@@ -886,8 +976,8 @@ class _Xenforo extends \IPS\convert\Software
catch( \UnderflowException $e )
{
/* Ut oh... do something random. */
$hash = md5( uniqid() );
$salt = md5( uniqid() );
$hash = md5( mt_rand() );
$salt = md5( mt_rand() );
}
/* IP Address */
@@ -1415,4 +1505,103 @@ class _Xenforo extends \IPS\convert\Software
return NULL;
}
/**
* Process a login
*
* @param \IPS\Member $member The member
* @param string $password Password from form
* @return bool
*/
public function login( $member, $password )
{
$password = html_entity_decode( $password );
// XF 1.2
require_once \IPS\ROOT_PATH . "/applications/convert/sources/Login/PasswordHash.php";
$ph = new \PasswordHash( 10, TRUE );
if ( $ph->CheckPassword( $password, $member->conv_password ) )
{
return TRUE;
}
// XF 1.1
if ( extension_loaded( 'hash' ) )
{
$hashedPassword = hash( 'sha256', hash( 'sha256', $password ) . $member->misc );
}
else
{
$hashedPassword = sha1( sha1( $password ) . $member->misc );
}
if ( \IPS\Login::compareHashes( $member->conv_password, $hashedPassword ) )
{
return TRUE;
}
// If they converted vB > XF > IPB then passwords may be in vB format still - try that.
return \IPS\convert\Software\Core\Vbulletin::login( $member, $password );
}
/**
* @brief Cache sprite image objects
*/
protected $_spriteImages = array();
/**
* Return image from sprite - We must use GD for this, it's generally available on most servers
* And we don't have any relevant methods in either image handler for doing this completly within
* the image class
*
* @param string $sprite Sprite path
* @param array $spriteParams Sprite parameters
* @return array
*/
protected function _emoticonsFromSprite( $sprite, $spriteParams )
{
$key = md5( $sprite );
/* Set up image canvas */
if( !isset( $this->_spriteImages[ $key ] ) )
{
if( !file_exists( $sprite ) )
{
return array( 'emoticon' => NULL );
}
$this->_spriteImages[ $key ] = new \IPS\Image\Gd( file_get_contents( $sprite ) );
}
/* x2 Emoticon? */
$multiplier = 1;
if( $this->_spriteImages[ $key ]->width > $spriteParams['w'] )
{
$multiplier = 2;
}
$emoticon = \IPS\Image\Gd::newImageCanvas( $spriteParams['w'] * $multiplier, $spriteParams['h'] * $multiplier, array( 0, 0, 0 ) );
/* Set the background to transparent */
imagefill( $emoticon->image, 0, 0, imagecolorallocatealpha( $emoticon->image, 0, 0, 0, 127 ) );
/* Extract sprite */
imagecopy( $emoticon->image, $this->_spriteImages[ $key ]->image, 0, 0, abs( $spriteParams['x'] ) * $multiplier, abs( $spriteParams['y'] ) * $multiplier, $spriteParams['w'] * $multiplier, $spriteParams['h'] * $multiplier );
/* x2 Emoticon? */
$return = array();
if( $multiplier == 2 )
{
$return['emoticon_x2'] = (string) $emoticon;
/* Resize */
$emoticon->resize( $spriteParams['w'], $spriteParams['h'] );
}
$return['emoticon'] = (string) $emoticon;
unset( $emoticon );
return $return;
}
}
@@ -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;
}
}
@@ -119,7 +119,8 @@ class _Bbpress extends \IPS\convert\Software
'id' => $row['ID'],
'name' => $row['post_title'],
'description' => $row['post_content'],
'parent_id' => $row['post_parent'],
'parent_id' => $row['post_parent'] ?: NULL,
'sub_can_post' => 1
);
$libraryClass->convertForumsForum( $info );
@@ -74,6 +74,21 @@ class _Expressionengine extends \IPS\convert\Software
);
}
/**
* Allows software to add additional menu row options
*
* @param array $rows Existing rows
* @return array
*/
public function extraMenuRows( $rows )
{
$rows['convertOtherPosts'] = $rows['convertForumsPosts'];
$rows['convertOtherPosts']['step_method'] = 'convertOtherPosts';
$rows['convertOtherPosts']['source_rows'] = $this->countRows( static::canConvert()['convertOtherPosts']['table'], static::canConvert()['convertOtherPosts']['where'] );
return $rows;
}
/**
* Requires Parent
*
@@ -0,0 +1,524 @@
<?php
/**
* @brief Converter Invision Community Class
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage Converter
* @since 26 July 2017
*/
namespace IPS\convert\Software\Forums;
/* 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' );
exit;
}
class _Invisioncommunity extends \IPS\convert\Software
{
/**
* @brief Whether the versions of IPS4 match
*/
public static $versionMatch = FALSE;
/**
* @brief Whether the database has been required
*/
public static $dbNeeded = FALSE;
public function __construct( \IPS\convert\App $app, $needDB=TRUE )
{
/* Set filename obscuring flag */
\IPS\convert\Library::$obscureFilenames = FALSE;
$return = parent::__construct( $app, $needDB );
if( $needDB )
{
static::$dbNeeded = TRUE;
$version = $this->db->select( 'app_version', 'core_applications', array( 'app_directory=?', 'core' ) )->first();
/* We're matching against the human version since the long version can change with patches */
if( $version == \IPS\Application::load( 'core')->version )
{
static::$versionMatch = TRUE;
}
/* Get parent sauce */
$this->parent = $this->app->get__parent()->getSource();
}
return $return;
}
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return 'Invision Community (' . \IPS\Application::load( 'core' )->version . ')';
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "invisioncommunity";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
if( !static::$versionMatch AND static::$dbNeeded )
{
throw new \IPS\convert\Exception( 'convert_invision_mismatch' );
}
return array(
'convertForumsForums' => array(
'table' => 'forums_forums',
'where' => NULL,
),
'convertForumsTopics' => array(
'table' => 'forums_topics',
'where' => NULL,
),
'convertForumsPosts' => array(
'table' => 'forums_posts',
'where' => NULL,
),
'convertForumsTopicsMultimods' => array(
'table' => 'forums_topic_mmod',
'where' => NULL,
),
'convertForumsRssImports' => array(
'table' => 'forums_rss_import',
'where' => NULL,
),
'convertForumsRssImported' => array(
'table' => 'forums_rss_imported',
'where' => NULL,
),
'convertForumsQuestionRatings' => array(
'table' => 'forums_question_ratings',
'where' => NULL,
),
'convertForumsAnswerRatings' => array(
'table' => 'forums_answer_ratings',
'where' => NULL,
),
'convertAttachments' => array(
'table' => 'core_attachments',
'where' => NULL
),
);
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertAttachments'
);
}
/**
* Get More Information
*
* @param string $method Method name
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertAttachments':
\IPS\Member::loggedIn()->language()->words["upload_path"] = \IPS\Member::loggedIn()->language()->addToStack( 'convert_invision_upload_input' );
\IPS\Member::loggedIn()->language()->words["upload_path_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'convert_invision_upload_input_desc' );
$return[ $method ] = array(
'upload_path' => array(
'field_class' => 'IPS\\Helpers\\Form\\Text',
'field_default' => isset( $this->parent->app->_session['more_info']['convertEmoticons']['upload_path'] ) ? $this->parent->app->_session['more_info']['convertEmoticons']['upload_path'] : NULL,
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack('convert_invision_upload_path'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
)
);
break;
}
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'invisioncommunity' ) );
}
/**
* Finish - Adds everything it needs to the queues and clears data store
*
* @return array Messages to display
*/
public function finish()
{
/* Content Rebuilds */
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\forums\Forum', 'count' => 0 ), 5, array( 'class' ) );
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\forums\Topic' ), 3, array( 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildFirstPostIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
\IPS\Task::queue( 'convert', 'DeleteEmptyTopics', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
\IPS\Task::queue( 'convert', 'InvisionCommunityRebuildContent', array( 'app' => $this->app->app_id, 'link' => 'forums_posts', 'class' => 'IPS\forums\Topic\Post' ), 2, array( 'app', 'link', 'class' ) );
/* Caches */
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'forums_topics', 'class' => 'IPS\forums\Topic' ), 3, array( 'app', 'link', 'class' ) );
/* Rebuild Leaderboard */
\IPS\Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
\IPS\Db::i()->delete('core_reputation_leaderboard_history');
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics", "f_topic_tags_recount" );
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id' );
foreach( $this->fetch( 'forums_forums', 'id' ) AS $row )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $row, 'forums_forums', 'forums' );
/* Add name after clearing other columns */
$row['name'] = $this->parent->getWord( 'forums_forum_' . $row['id'] );
$row['description'] = $this->parent->getWord( 'forums_forum_' . $row['id'] . '_desc' );
$libraryClass->convertForumsForum( $row );
/* Convert Follows */
foreach( $this->db->select( '*', 'core_follow', array( 'follow_app=? AND follow_area=? AND follow_rel_id=?', 'forums', 'forum', $row['id'] ) ) as $follow )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $follow, 'core_follow', 'core' );
/* Change follow data */
$follow['follow_rel_id_type'] = 'forums_forums';
$libraryClass->convertFollow( $follow );
}
$libraryClass->setLastKeyValue( $row['id'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'tid' );
foreach( $this->fetch( 'forums_topics', 'tid' ) AS $row )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $row, 'forums_topics', 'forums' );
$libraryClass->convertForumsTopic( $row );
/* Convert Follows */
foreach( $this->db->select( '*', 'core_follow', array( 'follow_app=? AND follow_area=? AND follow_rel_id=?', 'forums', 'topic', $row['tid'] ) ) as $follow )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $follow, 'core_follow', 'core' );
/* Change follow data */
$follow['follow_rel_id_type'] = 'forums_topics';
$libraryClass->convertFollow( $follow );
}
/* Convert Ratings */
foreach( $this->db->select( '*', 'core_ratings', array( 'class=? AND item_id=?', 'IPS\\forums\\Topic', $row['tid'] ) ) as $rating )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $rating, 'core_ratings', 'core' );
/* Change rating data */
$rating['item_link'] = 'forums_topics';
$libraryClass->convertRating( $rating );
}
/* Convert Tags */
foreach( $this->db->select( '*', 'core_tags', array( 'tag_meta_app=? AND tag_meta_area=? AND tag_meta_id=?', 'forums', 'forums', $row['tid'] ) ) as $tag )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $tag, 'core_tags', 'core' );
$libraryClass->convertTag( $tag );
}
$libraryClass->setLastKeyValue( $row['tid'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'pid' );
foreach( $this->fetch( 'forums_posts', 'pid' ) AS $row )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $row, 'forums_posts', 'forums' );
$libraryClass->convertForumsPost( $row );
/* Convert Edit History */
foreach( $this->db->select( '*', 'core_edit_history', array( 'class=? AND comment_id=?', 'IPS\\forums\\Topic\\Post', $row['pid'] ) ) as $history )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $history, 'core_edit_history', 'core' );
$libraryClass->convertEditHistory( $history );
}
/* Reputation */
foreach( $this->db->select( '*', 'core_reputation_index', array( "app=? AND type=? AND type_id=?", 'forums', 'pid', $row['pid'] ) ) AS $rep )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $rep, 'core_reputation_index', 'core' );
$libraryClass->convertReputation( $rep );
}
$libraryClass->setLastKeyValue( $row['pid'] );
}
}
/**
* Convert topics mmod
*
* @return void
*/
public function convertForumsTopicsMultimods()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'mm_id' );
foreach( $this->fetch( 'forums_topic_mmod', 'mm_id' ) AS $row )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $row, 'forums_topic_mmod', 'forums' );
/* Add name after clearing other columns */
$row['mm_name'] = $this->parent->getWord( 'forums_mmod_' . $row['mm_id'] );
$libraryClass->convertForumsTopicMultimod( $row );
$libraryClass->setLastKeyValue( $row['mm_id'] );
}
}
/**
* Convert rss imports
*
* @return void
*/
public function convertForumsRssImports()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'rss_import_id' );
foreach( $this->fetch( 'forums_rss_import', 'rss_import_id' ) AS $row )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $row, 'forums_rss_import', 'forums' );
$libraryClass->convertForumsRssImport( $row );
$libraryClass->setLastKeyValue( $row['rss_import_id'] );
}
}
/**
* Convert rss imported
*
* @return void
*/
public function convertForumsRssImported()
{
$libraryClass = $this->getLibrary();
foreach( $this->fetch( 'forums_rss_imported', 'rss_imported_tid' ) AS $row )
{
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $row, 'forums_rss_imported', 'forums' );
$libraryClass->convertForumsRssImported( $row );
}
}
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'attach_id' );
foreach( $this->fetch( 'core_attachments', 'attach_id' ) AS $row )
{
try
{
$attachmentMap = $this->db->select( '*', 'core_attachments_map', array( 'attachment_id=? AND location_key=?', $row['attach_id'], 'forums_Forums' ) )->first();
}
catch( \UnderflowException $e )
{
$libraryClass->setLastKeyValue( $row['attach_id'] );
continue;
}
/* Remove non-standard columns */
$this->parent->unsetNonStandardColumns( $row, 'core_attachments' );
$this->parent->unsetNonStandardColumns( $attachmentMap, 'core_attachments_map' );
/* Remap rows */
$name = explode( '/', $row['attach_location'] );
$row['attach_container'] = isset( $name[1] ) ? $name[0] : NULL;
$thumbName = explode( '/', $row['attach_thumb_location'] );
$row['attach_thumb_container'] = isset( $thumbName[1] ) ? $thumbName[0] : NULL;
$filePath = $this->app->_session['more_info']['convertAttachments']['upload_path'] . '/' . $row['attach_location'];
$thumbnailPath = $this->app->_session['more_info']['convertAttachments']['upload_path'] . '/' . $row['attach_thumb_location'];
unset( $row['attach_file'] );
$libraryClass->convertAttachment( $row, $attachmentMap, $filePath, NULL, $thumbnailPath );
$libraryClass->setLastKeyValue( $row['attach_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( '#/ips4merge/(forum|topic)/([0-9]+)-(.+?)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$oldId = (int) $matches[2];
switch( $matches[1] )
{
case 'forum':
$class = '\IPS\forums\Forum';
$types = array( 'forums', 'forums_forums' );
break;
case 'topic':
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
if( \IPS\Request::i()->do == 'findComment' AND \IPS\Request::i()->comment )
{
$class = '\IPS\forums\Topic\Post';
$types = array( 'posts', 'forums_posts' );
$oldId = \IPS\Request::i()->comment;
}
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;
}
}
@@ -185,6 +185,17 @@ class _Mybb extends \IPS\convert\Software
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics", "f_topic_tags_recount" );
}
/**
* Fix Post Data
*
* @param string Post
* @return string Fixed Posts
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\Mybb::fixPostData( $post );
}
/**
* Convert forums
*
@@ -237,7 +248,6 @@ class _Mybb extends \IPS\convert\Software
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -413,7 +423,6 @@ class _Mybb extends \IPS\convert\Software
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -498,7 +507,7 @@ class _Mybb extends \IPS\convert\Software
/* Warnings */
foreach( $this->db->select( '*', 'warnings', array( "pid=?", $row['pid'] ) ) AS $warn )
{
$libraryClass->convertWarnLog( array(
$warnId = $libraryClass->convertWarnLog( array(
'wl_id' => $warn['wid'],
'wl_member' => $warn['uid'],
'wl_moderator' => $warn['issuedby'],
@@ -506,6 +515,17 @@ class _Mybb extends \IPS\convert\Software
'wl_points' => $warn['points'],
'wl_note_mods' => $warn['notes'],
) );
/* Add a member history record for this member */
$libraryClass->convertMemberHistory( array(
'log_id' => 'w' . $warn['wid'],
'log_member' => $warn['uid'],
'log_by' => $warn['issuedby'],
'log_type' => 'warning',
'log_data' => array( 'wid' => $warnId ),
'log_date' => $warn['dateline']
)
);
}
$libraryClass->setLastKeyValue( $row['pid'] );
@@ -28,7 +28,7 @@ class _Phpbb extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "phpBB 3.x";
return "phpBB (3.1.x/3.2.x)";
}
/**
@@ -229,7 +229,6 @@ class _Phpbb extends \IPS\convert\Software
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -371,7 +370,6 @@ class _Phpbb extends \IPS\convert\Software
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -495,10 +493,24 @@ class _Phpbb extends \IPS\convert\Software
$post = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
$attachmentName = preg_quote( $row['real_filename'], '/' );
if ( preg_match( "/\[attachment=(.+?)?\]\<\!\-\- ia0 \-\-\>{$attachmentName}\<\!\-\- ia0 \-\-\>\[\/attachment\]/i", $post ) )
{
$post = preg_replace( "/\[attachment=(.+?)?\]\<\!\-\- ia0 \-\-\>{$attachmentName}\<\!\-\- ia0 \-\-\>\[\/attachment\]/i", '[attachment=' . $attachId . ':name]', $post );
$regex31 = '/\[attachment=(.+?)?\]\<\!\-\- ia[\d]+ \-\-\>' . $attachmentName . '\<\!\-\- ia[\d]+ \-\-\>\[\/attachment\]/i';
$regex32 = '/\<ATTACHMENT filename\="(.+?)?" index\="(.+?)?"\>\<s\>\[attachment\=(.+?)?\]\<\/s\>' . $attachmentName . '<e\>\[\/attachment\]\<\/e\>\<\/ATTACHMENT\>/i';
$changed = FALSE;
if( preg_match( $regex31, $post ) )
{
$changed = TRUE;
$post = preg_replace( $regex31, '[attachment=' . $attachId . ':name]', $post );
}
elseif( preg_match( $regex32, $post ) )
{
$changed = TRUE;
$post = preg_replace( $regex32, '[attachment=' . $attachId . ':name]', $post );
}
if( $changed )
{
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
}
}
@@ -28,7 +28,7 @@ class _Punbb extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "PunBB 1.x";
return "PunBB (1.x)";
}
/**
@@ -249,7 +249,6 @@ class _Punbb extends \IPS\convert\Software
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -29,7 +29,7 @@ class _Smf extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "Simple Machines Forum";
return "Simple Machines Forum (2.0.x)";
}
/**
@@ -75,6 +75,21 @@ class _Smf extends \IPS\convert\Software
);
}
/**
* Allows software to add additional menu row options
*
* @param array $rows Existing rows
* @return array
*/
public function extraMenuRows( $rows )
{
$rows['convertForumsBoards'] = $rows['convertForumsForums'];
$rows['convertForumsBoards']['step_method'] = 'convertForumsBoards';
$rows['convertForumsBoards']['source_rows'] = $this->countRows( static::canConvert()['convertForumsBoards']['table'], static::canConvert()['convertForumsBoards']['where'] );
return $rows;
}
/**
* Count Source Rows for a specific step
*
@@ -366,7 +381,6 @@ class _Smf extends \IPS\convert\Software
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -83,6 +83,47 @@ class _UBBthreads extends \IPS\convert\Software
);
}
/**
* Allows software to add additional menu row options
*
* @param array $rows Existing rows
* @return array
*/
public function extraMenuRows( $rows )
{
$count = $this->countRows( static::canConvert()['convertForumsTopicsRatings']['table'], static::canConvert()['convertForumsTopicsRatings']['where'] );
if( $count )
{
$rows['convertForumsTopicsRatings'] = array(
'step_method' => 'convertForumsTopicsRatings',
'step_title' => 'convert_ratings',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_ratings' )->first(),
'source_rows' => $count,
'per_cycle' => 1500,
'dependencies' => array( 'convertForumsTopics' ),
'link_type' => 'topic_ratings',
);
}
$count = $this->countRows( static::canConvert()['convertForumsTopicsFollowers']['table'], static::canConvert()['convertForumsTopicsFollowers']['where'] );
if( $count )
{
$rows['convertForumsTopicsFollowers'] = array(
'step_method' => 'convertForumsTopicsFollowers',
'step_title' => 'convert_follows',
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'core_follow' )->first(),
'source_rows' => $count,
'per_cycle' => 1000,
'dependencies' => array( 'convertForumsTopics' ),
'link_type' => 'core_follows',
);
}
return $rows;
}
/**
* Count Source Rows for a specific step
*
@@ -247,7 +288,7 @@ class _UBBthreads extends \IPS\convert\Software
{
$libraryClass = $this->getLibrary();
foreach ( $this->fetch( 'WATCH_LISTS', 'WATCH_ID', array( 'WATCH_TYPE=?', 'f' ), 'USER_ID ASC, WATCH_ID ASC' ) as $row )
foreach ( $this->fetch( 'WATCH_LISTS', 'WATCH_ID', array( 'WATCH_TYPE=?', 'f' ) ) as $row )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
@@ -390,7 +431,7 @@ class _UBBthreads extends \IPS\convert\Software
{
$libraryClass = $this->getLibrary();
foreach ( $this->fetch( 'WATCH_LISTS', 'WATCH_ID', array( 'WATCH_TYPE=?', 't' ), 'USER_ID ASC, WATCH_ID ASC' ) as $row )
foreach ( $this->fetch( 'WATCH_LISTS', 'WATCH_ID', array( 'WATCH_TYPE=?', 't' ) ) as $row )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
@@ -489,7 +530,25 @@ class _UBBthreads extends \IPS\convert\Software
return NULL;
}
if( preg_match( '#/ubbthreads.php/topics/([0-9]+)($|/)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
//ubbthreads.php?ubb=showflat&Number=?
if( isset( \IPS\Request::i()->Number ) AND isset( \IPS\Request::i()->ubb ) )
{
try
{
$data = (string) $this->app->getLink( (int) \IPS\Request::i()->Number, array( 'posts', 'forums_posts' ) );
$post = \IPS\forums\Topic\Post::load( $data );
if( $post->item()->canView() )
{
return $post->url();
}
}
catch ( \OutOfRangeException $e )
{
return NULL;
}
}
elseif( preg_match( '#/ubbthreads.php/topics/([0-9]+)($|/)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
try
{
@@ -510,6 +569,18 @@ class _UBBthreads extends \IPS\convert\Software
}
catch( \Exception $e )
{
try
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'posts', 'forums_posts' ) );
$post = \IPS\forums\Topic\Post::load( $data );
if( $post->item()->canView() )
{
return $post->url();
}
}
catch ( \OutOfRangeException $e ) { }
return NULL;
}
}
@@ -530,6 +601,23 @@ class _UBBthreads extends \IPS\convert\Software
return NULL;
}
}
elseif( preg_match( '#ubbthreads.php/ubb/showflat/Number/([0-9]+)($|/)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
try
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'posts', 'forums_posts' ) );
$post = \IPS\forums\Topic\Post::load( $data );
if( $post->item()->canView() )
{
return $post->url();
}
}
catch ( \OutOfRangeException $e )
{
return NULL;
}
}
return NULL;
}
@@ -20,6 +20,31 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
class _Vanilla extends \IPS\convert\Software
{
/**
* @brief Store the result of the check for reaction support
*/
protected static $_supportsReactions = FALSE;
/**
* 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 );
/* Check for reaction support - This is a Vanilla2 addon, so it may not be installed */
if ( $needDB )
{
static::$_supportsReactions = $this->db->checkForTable( 'Action' );
}
return $return;
}
/**
* Software Name
*
@@ -28,7 +53,7 @@ class _Vanilla extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "Vanilla 2";
return "Vanilla 2 (2.2.x/2.3.x)";
}
/**
@@ -94,6 +119,20 @@ class _Vanilla extends \IPS\convert\Software
);
}
/**
* Allows software to add additional menu row options
*
* @param array $rows Existing rows
* @return array
*/
public function extraMenuRows( $rows )
{
$rows['convertForumsPosts2'] = $rows['convertForumsPosts'];
$rows['convertForumsPosts2']['step_method'] = 'convertForumsPosts2';
return $rows;
}
/**
* Count Source Rows for a specific step
*
@@ -170,30 +209,33 @@ class _Vanilla extends \IPS\convert\Software
);
break;
case 'convertForumsPosts':
/* Get our reactions to let the admin map them */
$options = array();
$descriptions = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_reactions' ), 'IPS\Content\Reaction' ) AS $reaction )
/* Get our reactions to let the admin map them - this is a Vanilla2 addon so it may not be installed */
if( static::$_supportsReactions )
{
$options[ $reaction->id ] = $reaction->_icon->url;
$descriptions[ $reaction->id ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id ) . '<br>' . $reaction->_description;
}
$options = array();
$descriptions = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_reactions' ), 'IPS\Content\Reaction' ) AS $reaction )
{
$options[ $reaction->id ] = $reaction->_icon->url;
$descriptions[ $reaction->id ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id ) . '<br>' . $reaction->_description;
}
$return['convertForumsPosts'] = array();
$return['convertForumsPosts'] = array();
foreach( $this->db->select( '*', 'action' ) as $reaction )
{
\IPS\Member::loggedIn()->language()->words['reaction_' . $reaction['ActionID'] ] = $reaction['Name'];
\IPS\Member::loggedIn()->language()->words['reaction_' . $reaction['ActionID'] . '_desc' ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_convert_help');
foreach( $this->db->select( '*', 'Action' ) as $reaction )
{
\IPS\Member::loggedIn()->language()->words['reaction_' . $reaction['ActionID'] ] = $reaction['Name'];
\IPS\Member::loggedIn()->language()->words['reaction_' . $reaction['ActionID'] . '_desc' ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_convert_help');
$return['convertForumsPosts']['reaction_' . $reaction['ActionID'] ] = array(
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array( 'parse' => 'image', 'options' => $options, 'descriptions' => $descriptions ),
'field_hint' => NULL,
'field_validation' => NULL,
);
$return['convertForumsPosts']['reaction_' . $reaction['ActionID'] ] = array(
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array( 'parse' => 'image', 'options' => $options, 'descriptions' => $descriptions ),
'field_hint' => NULL,
'field_validation' => NULL,
);
}
}
break;
case 'convertAttachments':
@@ -246,16 +288,21 @@ class _Vanilla extends \IPS\convert\Software
public static function fixPostData( $post )
{
/**
* Vanilla actually only supports plaintext posts out of the box, but there is a popular quotes plugin I think
* we should accommodate for.
* Vanilla has a quotes plugin that seems to have changed formats quite often. - We'll try to match as many formats as we can
*/
$quoted = preg_replace_callback( '#<blockquote class="Quote" rel="([^"]+)">(.+)</blockquote>#', function( $match )
{
$match[1] = str_replace( '"', '', $match[1] );
return "[quote name=\"{$match[1]}\"]{$match[2]}[/quote]";
}, $post );
$post = preg_replace( '/(?:<blockquote\s+(?:class=\"(?:User)?Quote\")?(?:\s+rel=\"(?:[^\"]+)\")?>)(?:\s+)?<div class=\"QuoteAuthor\">([^\"]+)<\/div>(?:\s+)?<div class=\"QuoteText\">(?:<p>)?(.*?)(?:<\/p>)?<\/div>(?:\s+)?<\/blockquote>/i',
'[quote name="$1"]$2[/quote]' ,
$post );
return $quoted ?: $post;
$post = preg_replace( '/(?:<blockquote\s+(?:class=\"Quote (?:User)?Quote\")?(?:\s+rel=\"(?:[^\"]+)\")?>)(?:\s+)?<div class=\"QuoteText\">(?:<p>)?(.*?)(?:<\/p>)?<\/div>(?:\s+)?<\/blockquote>/i',
'[quote]$1[/quote]' ,
$post );
$post = preg_replace( '/<blockquote\s+rel=\"([^\"]+)\"?>(.*?)<\/blockquote>/i',
'[quote name="$1"]$2[/quote]' ,
$post );
return $post;
}
/**
@@ -374,16 +421,24 @@ class _Vanilla extends \IPS\convert\Software
foreach( $discussions AS $row )
{
$row['DateLastComment'] = 0;
$row['LastCommentUserID'] = 0;
$row['LastCommentUserName'] = '';
/* If last post info is empty, fetch it */
if( $row['DateLastComment'] === NULL )
{
$data = $this->db->select( 'Comment.InsertUserID, Comment.DateInserted, User.Name', 'Comment', array( 'DiscussionID=?', $row['DiscussionID'] ), 'CommentID DESC', array( 0, 1 ) )
->join( 'User', 'Comment.InsertUserID=User.UserID' )
->first();
try
{
$data = $this->db->select( 'Comment.InsertUserID, Comment.DateInserted, User.Name', 'Comment', array( 'DiscussionID=?', $row['DiscussionID'] ), 'CommentID DESC', array( 0, 1 ) )
->join( 'User', 'Comment.InsertUserID=User.UserID' )
->first();
$row['DateLastComment'] = $data['DateInserted'];
$row['LastCommentUserID'] = $data['InsertUserId'];
$row['LastCommentUserName'] = $data['Name'];
$row['DateLastComment'] = $data['DateInserted'];
$row['LastCommentUserID'] = $data['InsertUserId'];
$row['LastCommentUserName'] = $data['Name'];
}
catch( \UnderflowException $e ) {}
}
$info = array(
@@ -472,21 +527,24 @@ class _Vanilla extends \IPS\convert\Software
$libraryClass->convertForumsPost( $info );
$libraryClass->setLastKeyValue( $row['DiscussionID'] );
/* Reputation */
foreach( $this->db->select( '*', 'reaction', array( "ParentType=? AND ParentID=?", 'comment', $row['DiscussionID'] ) ) AS $rep )
/* Reputation - Reactions are only supported if the YAGA addon was used. */
if( static::$_supportsReactions )
{
$reaction = $this->app->_session['more_info']['convertForumsPosts']['reaction_' . $rep['ActionID'] ];
foreach( $this->db->select( '*', 'Reaction', array( "ParentType=? AND ParentID=?", 'comment', $row['DiscussionID'] ) ) AS $rep )
{
$reaction = $this->app->_session['more_info']['convertForumsPosts']['reaction_' . $rep['ActionID'] ];
$libraryClass->convertReputation( array(
'id' => $rep['ReactionID'],
'app' => 'forums',
'type' => 'pid',
'type_id' => 'fp-' . $row['DiscussionID'],
'member_id' => $rep['InsertUserID'],
'member_received' => $rep['ParentAuthorID'],
'rep_date' => VanillaCore::mysqlToDateTime( $row['DateInserted'] ),
'reaction' => $reaction
) );
$libraryClass->convertReputation( array(
'id' => $rep['ReactionID'],
'app' => 'forums',
'type' => 'pid',
'type_id' => 'fp-' . $row['DiscussionID'],
'member_id' => $rep['InsertUserID'],
'member_received' => $rep['ParentAuthorID'],
'rep_date' => VanillaCore::mysqlToDateTime( $row['DateInserted'] ),
'reaction' => $reaction
) );
}
}
}
}
@@ -170,7 +170,7 @@ class _Vbulletin extends \IPS\convert\Software
/* Content Rebuilds */
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\forums\Forum', 'count' => 0 ), 5, array( 'class' ) );
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'forums_posts', 'class' => 'IPS\forums\Topic\Post' ), 2, array( 'app', 'link', 'class' ) );
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\forums\Topic' ), 3, array( 'class' ) );
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\forums\Topic' ), 2, array( 'class' ) ); // This must run before the CMS item count task runs.
\IPS\Task::queue( 'convert', 'RebuildFirstPostIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
\IPS\Task::queue( 'convert', 'DeleteEmptyTopics', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
@@ -365,7 +365,6 @@ class _Vbulletin extends \IPS\convert\Software
'follow_notify_freq' => $frequency,
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -521,7 +520,6 @@ class _Vbulletin extends \IPS\convert\Software
'follow_notify_freq' => $frequency,
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
@@ -660,7 +658,7 @@ class _Vbulletin extends \IPS\convert\Software
/* Warnings */
foreach( $this->db->select( '*', 'infraction', array( "postid=?", $post['postid'] ) ) AS $warn )
{
$libraryClass->convertWarnLog( array(
$warnId = $libraryClass->convertWarnLog( array(
'wl_id' => $warn['infractionid'],
'wl_member' => $warn['userid'],
'wl_moderator' => $warn['whoadded'],
@@ -669,6 +667,17 @@ class _Vbulletin extends \IPS\convert\Software
'wl_note_member' => $warn['note'],
'wl_note_mods' => $warn['customreason'],
) );
/* Add a member history record for this member */
$libraryClass->convertMemberHistory( array(
'log_id' => 'w' . $warn['infractionid'],
'log_member' => $warn['userid'],
'log_by' => $warn['whoadded'],
'log_type' => 'warning',
'log_data' => array( 'wid' => $warnId ),
'log_date' => $warn['dateline']
)
);
}
/* If we have a latest edit, then update the main post - this should really be in the library, as the converters should not be altering data */
@@ -715,6 +724,7 @@ class _Vbulletin extends \IPS\convert\Software
{
/* If the topic is missing, there isn't much we can do. */
$libraryClass->setLastKeyValue( $attachment['attachmentid'] );
$this->app->log( 'vb_attach_missing_topic', __METHOD__, \IPS\convert\App::LOG_WARNING, $attachment['attachmentid'] );
continue;
}
@@ -728,6 +738,7 @@ class _Vbulletin extends \IPS\convert\Software
{
/* 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'] );
continue;
}
}
@@ -965,21 +976,29 @@ class _Vbulletin extends \IPS\convert\Software
\IPS\Request::i()->t = $matches[1];
\IPS\Request::i()->page = $matches[2];
}
/* Normal Topics */
elseif( preg_match( "/\/(\d+)\-.+?\.html/", $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$url = $url->setPath( preg_replace( "/\/(\d+)\-.+?\.html/", "/showthread.php", $url->data[ \IPS\Http\Url::COMPONENT_PATH ] ) )->setQueryString( 't', $matches[1] );
\IPS\Request::i()->t = $matches[1];
}
/* Post Links */
elseif( preg_match( "/\/(\d+)\-.+?\-post(\d+)\.html/", $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$url = $url->setPath( preg_replace( "/\/(\d+)\-.+?\-post(\d+)\.html/", "/showpost.php", $url->data[ \IPS\Http\Url::COMPONENT_PATH ] ) )->setQueryString( 'p', $matches[2] );
\IPS\Request::i()->p = $matches[2];
}
}
/* Forum URLs are the same across VB 3.8 and VB 4 */
if( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'forumdisplay.php' ) !== FALSE )
{
/* Forum URLs can be in one of 3 formats really...
* /forumdisplay.php/1-name
* /forums/1-name
* /forumdisplay.php?f=1
*/
/* Forum URLs can be in one of 4 formats really...
* /forumdisplay.php/1-name
* /forums/1-name
* /forumdisplay.php?f=1
* /forumdisplay.php?1-name
*/
$path = $url->data[ \IPS\Http\Url::COMPONENT_PATH ];
if( mb_strpos( $path, 'forumdisplay.php' ) !== FALSE )
{
@@ -987,6 +1006,10 @@ class _Vbulletin extends \IPS\convert\Software
{
$oldId = \IPS\Request::i()->f;
}
elseif( preg_match( '#^(\d+)-[^/]+#i', $url->data[ \IPS\Http\Url::COMPONENT_QUERY ], $matches ) )
{
$oldId = $matches[1];
}
else
{
$queryStringPieces = explode( '-', mb_substr( $path, mb_strpos( $path, 'forumdisplay.php/' ) + mb_strlen( 'forumdisplay.php/' ) ) );
@@ -1064,11 +1087,12 @@ class _Vbulletin extends \IPS\convert\Software
/* And then topic URLs, same idea */
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'showthread.php' ) !== FALSE )
{
/* Topic URLs can be in one of 3 formats really...
* /showthread.php/1-name
* /threads/1-name
* /showthread.php?t=1
*/
/* Topic URLs can be in one of 4 formats really...
* /showthread.php/1-name
* /threads/1-name
* /showthread.php?t=1
* /showthread.php?1-name
*/
$path = $url->data[ \IPS\Http\Url::COMPONENT_PATH ];
if( mb_strpos( $path, 'showthread.php' ) !== FALSE )
{
@@ -1076,6 +1100,10 @@ class _Vbulletin extends \IPS\convert\Software
{
$oldId = \IPS\Request::i()->t;
}
elseif( preg_match( '#^(\d+)-[^/]+#i', $url->data[ \IPS\Http\Url::COMPONENT_QUERY ], $matches ) )
{
$oldId = $matches[1];
}
else
{
$queryStringPieces = explode( '-', mb_substr( $path, mb_strpos( $path, 'showthread.php/' ) + mb_strlen( 'showthread.php/' ) ) );
@@ -1156,7 +1184,7 @@ class _Vbulletin extends \IPS\convert\Software
}
catch( \OutOfRangeException $e )
{
$data = $this->getLink( (string) $parameters[1], array( 'topics', 'forums_topics', FALSE, TRUE ) );
$data = $this->getLink( (string) $parameters[1], array( 'topics', 'forums_topics' ), FALSE, TRUE );
}
$item = \IPS\forums\Topic::load( $data );
@@ -91,7 +91,7 @@ class _Vbulletin5 extends \IPS\convert\Software
break;
case 'post':
return parent::countRows( 'node', array( \IPS\Db::i()->in( 'contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ) ) ) ) );
return parent::countRows( 'node', array( \IPS\Db::i()->in( 'contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ), $this->fetchType( 'Poll' ) ) ) ) );
break;
case 'attachment':
@@ -235,8 +235,19 @@ class _Vbulletin5 extends \IPS\convert\Software
$libraryClass::setKey( 'node.nodeid' );
$clubs = $this->fetchClubs();
foreach( $this->fetch( 'node', 'nodeid', array( "node.nodeid<>2 AND ( ( node.parentid=? AND node.contenttypeid=? ) OR " . $this->db->in( 'nodeid', array_keys( $clubs ) ) . " )", $this->fetchType( 'Thread' ), $this->fetchType( 'Channel' ) ) ) AS $forum )
foreach( $this->fetch( 'node', 'nodeid', array( "node.nodeid<>? AND ( ( closure.parent=? AND node.contenttypeid=? ) OR " . $this->db->in( 'nodeid', array_keys( $clubs ) ) . " )", 2, 2, $this->fetchType( 'Channel' ) ) )->join( 'closure', "closure.child=node.nodeid" ) AS $forum )
{
/* This may be a club forum that already exists */
try
{
$this->app->getLink( $forum['nodeid'], 'forums_forums' );
$libraryClass->setLastKeyValue( $forum['nodeid'] );
$this->app->log( 'vb5_skipped_forum', __METHOD__, \IPS\convert\App::LOG_WARNING );
continue;
}
catch( \OutOfRangeException $e ){}
$self = $this;
$checkpermission = function( $name, $perm ) use ( $forum, $self )
{
@@ -441,16 +452,33 @@ class _Vbulletin5 extends \IPS\convert\Software
{
/* Actually, we don't - end of the line */
$libraryClass->setLastKeyValue( $post['nodeid'] );
$this->app->log( 'vb5_post_missing_parent_post', __METHOD__, \IPS\convert\App::LOG_WARNING, $post['nodeid'] );
continue;
}
catch( \UnderflowException $e )
{
/* Loading the parent failed - move on */
$libraryClass->setLastKeyValue( $post['nodeid'] );
$this->app->log( 'vb5_post_missing_parent_post_2', __METHOD__, \IPS\convert\App::LOG_WARNING, $post['nodeid'] );
continue;
}
}
}
/* We may need to insert some data in core_soft_delete_log later if the post was hidden by a moderator. */
$softDeleted = FALSE;
$queued = 0;
if ( !$post['approved'] )
{
/* If the post is unapproved, then that's a direct translation and the post should then be marked as hidden pending approval. */
$queued = 1;
}
else if ( $post['deleteuserid'] )
{
$queued = -1;
$softDeleted = TRUE;
}
$info = array(
'pid' => $post['nodeid'],
'topic_id' => $post['parentid'],
@@ -459,12 +487,25 @@ class _Vbulletin5 extends \IPS\convert\Software
'author_name' => $post['authorname'],
'ip_address' => $post['ipaddress'],
'post_date' => $post['publishdate'],
'queued' => $post['approved'] ? 0 : -1,
'queued' => $queued,
'post_htmlstate' => ( in_array( $post['htmlstate'], array( 'on', 'on_nl2br' ) ) ) ? 1 : 0,
);
$post_id = $libraryClass->convertForumsPost( $info );
/* Need to insert into the SDL? */
if ( $softDeleted )
{
\IPS\Db::i()->insert( 'core_soft_delete_log', array(
'sdl_obj_id' => $post_id,
'sdl_obj_key' => 'post',
'sdl_obj_member_id' => $this->app->getLink( $post['deleteuserid'], 'core_members', TRUE ),
'sdl_obj_date' => $post['unpublishdate'] ?: time(),
'sdl_obj_reason' => $post['deletereason'] ?: NULL,
'sdl_locked' => 0
) );
}
/* Reputation */
foreach( $this->db->select( '*', 'reputation', array( "nodeid=?", $post['nodeid'] ) ) AS $rep )
{
@@ -511,7 +552,7 @@ class _Vbulletin5 extends \IPS\convert\Software
/* Warnings */
foreach( $this->db->select( '*', 'infraction', array( "nodeid=?", $post['nodeid'] ) ) AS $warn )
{
$libraryClass->convertWarnLog( array(
$warnId = $libraryClass->convertWarnLog( array(
'wl_id' => $warn['infractionid'],
'wl_member' => $warn['nodeid'],
'wl_moderator' => $warn['whoadded'],
@@ -520,6 +561,17 @@ class _Vbulletin5 extends \IPS\convert\Software
'wl_note_member' => $warn['note'],
'wl_note_mods' => $warn['customreason'],
) );
/* Add a member history record for this member */
$libraryClass->convertMemberHistory( array(
'log_id' => 'w' . $warn['infractionid'],
'log_member' => $warn['userid'],
'log_by' => $warn['whoadded'],
'log_type' => 'warning',
'log_data' => array( 'wid' => $warnId ),
'log_date' => $warn['dateline']
)
);
}
/* If we have a latest edit, then update the main post - this should really be in the library, as the converters should not be altering data */
@@ -566,12 +618,16 @@ class _Vbulletin5 extends \IPS\convert\Software
}
catch( \OutOfRangeException $e )
{
/* No valid converter link for the parent post */
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
$this->app->log( 'vb5_attach_missing_post_link', __METHOD__, \IPS\convert\App::LOG_WARNING, $attachment['nodeid'] );
continue;
}
catch( \UnderflowException $e )
{
/* Parent post does not exist in vB database */
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
$this->app->log( 'vb5_attach_missing_post', __METHOD__, \IPS\convert\App::LOG_WARNING, $attachment['nodeid'] );
continue;
}
}
@@ -644,6 +700,7 @@ class _Vbulletin5 extends \IPS\convert\Software
else
{
$oldAttachId = NULL;
$update = FALSE;
/* Try old attach ID */
try
@@ -655,8 +712,17 @@ class _Vbulletin5 extends \IPS\convert\Software
if ( $oldAttachId !== NULL and preg_match( "/\[ATTACH=(.+?)?\]" . $oldAttachId . "\[\/ATTACH\]/i", $post ) )
{
$update = TRUE;
$post = preg_replace( "/\[ATTACH(.+?)?\]" . $oldAttachId . "\[\/ATTACH\]/i", '[attachment=' . $attach_id . ':name]', $post );
}
elseif( preg_match( "/\[ATTACH=JSON](.+?)\"data-attachmentid\":\"?{$attachment['nodeid']}\"?(.+?)\[\/ATTACH\]/i", $post ) )
{
$update = TRUE;
$post = preg_replace( "/\[ATTACH=JSON](.+?)\"data-attachmentid\":\"?{$attachment['nodeid']}\"?(.+?)\[\/ATTACH\]/i", '[attachment=' . $attach_id . ':name]', $post );
}
if( $update )
{
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
}
}
@@ -20,11 +20,53 @@ 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 Flag to indicate the post data has been fixed during conversion, and we only need to use Legacy Parser
*/
public static $contentFixed = TRUE;
/**
* 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::$isLegacy = FALSE;
}
}
}
catch( \Exception $e ) {} # If we can't query, we won't be able to do anything anyway
}
return $return;
}
/**
* Software Name
*
@@ -33,7 +75,7 @@ class _Xenforo extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "XenForo";
return "XenForo (1.5.x/2.0.x)";
}
/**
@@ -187,17 +229,19 @@ class _Xenforo extends \IPS\convert\Software
{
return \IPS\convert\Software\Core\Xenforo::fixPostData( $post );
}
/**
* 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 )
@@ -273,7 +317,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
) );
}
@@ -418,14 +461,13 @@ class _Xenforo extends \IPS\convert\Software
'follow_notify_freq' => ( $follow['email_subscribe'] ) ? 'immediate' : 'none',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
/* Tag Prefix */
if ( $row['prefix_id'] )
{
$prefix = $this->getPhrase( "thread_prefix_{$row['prefix_id']}" );
$prefix = $this->getPhrase( "thread_prefix_{$row['prefix_id']}", "thread_prefix.{$row['prefix_id']}" );
if ( !is_null( $prefix ) )
{
@@ -519,12 +561,23 @@ class _Xenforo extends \IPS\convert\Software
$queued = 2;
break;
}
$editName = NULL;
try
{
if( $row['last_edit_user_id'] )
{
$editName = $this->db->select( 'username', 'xf_user', array( 'user_id=?', $row['last_edit_user_id'] ) )->first();
}
}
catch( \UnderflowException $e ) {}
$info = array(
'pid' => $row['post_id'],
'topic_id' => $row['thread_id'],
'post' => static::fixPostData( $row['message'] ),
'edit_time' => $row['last_edit_date'],
'edit_name' => $editName,
'author_id' => $row['user_id'],
'author_name' => $row['username'],
'ip_address' => $ip,
@@ -555,7 +608,7 @@ class _Xenforo extends \IPS\convert\Software
/* Warnings */
foreach( $this->db->select( '*', 'xf_warning', array( "content_type=? AND content_id=?", 'post', $row['post_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'],
@@ -564,6 +617,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']
)
);
}
/* Edit History */
@@ -28,7 +28,7 @@ class _Coppermine extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "Coppermine";
return "Coppermine (phpBB 3.1.x/3.2.x)";
}
/**
@@ -144,6 +144,7 @@ class _Coppermine 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' ) );
@@ -111,6 +111,7 @@ class _Photoplog 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' ) );
@@ -29,7 +29,7 @@ class _Photopost extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "Photopost";
return "Photopost (8.x)";
}
/**
@@ -43,6 +43,26 @@ class _Photopost extends \IPS\convert\Software
return "photopost";
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'photopost' ) );
}
/**
* Content we can convert from this software.
*
@@ -50,7 +70,226 @@ class _Photopost extends \IPS\convert\Software
*/
public static function canConvert()
{
return NULL;
return array(
'convertGalleryCategories' => array(
'table' => 'categories',
'where' => array( 'cattype=?', 'c' )
),
'convertGalleryAlbums' => array(
'table' => 'categories',
'where' => array( 'cattype=?', 'a' )
),
'convertGalleryImages' => array(
'table' => 'photos',
'where' => NULL,
),
'convertGalleryComments' => array(
'table' => 'comments',
'where' => NULL,
)
);
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertGalleryAlbums',
'convertGalleryImages'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertGalleryAlbums':
$options = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'gallery_categories' ), 'IPS\gallery\Category' ) AS $category )
{
$options[$category->_id] = $category->_title;
}
$return['convertGalleryAlbums']['members_gallery_category'] = array(
'field_class' => 'IPS\\Helpers\\Form\\Select',
'field_default' => NULL,
'field_required' => FALSE,
'field_extra' => array(
'options' => $options
),
'field_hint' => NULL,
);
break;
case 'convertGalleryImages':
$return['convertGalleryImages']['file_location'] = array(
'field_class' => 'IPS\\Helpers\\Form\\Text',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => array(),
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack('convert_photopost_image_path'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
);
break;
}
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
}
/**
* Finish - Adds everything it needs to the queues and clears data store
*
* @return array Messages to display
*/
public function finish()
{
/* 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' ) );
return array( "f_gallery_images_rebuild", "f_gallery_cat_recount", "f_gallery_album_recount", "f_gallery_image_recount" );
}
/**
* Convert gallery categories
*
* @return void
*/
public function convertGalleryCategories()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id' );
foreach( $this->fetch( 'categories', 'id', array( 'cattype=?', 'c' ) ) AS $row )
{
$libraryClass->convertGalleryCategory( array(
'category_id' => $row['id'],
'category_name' => html_entity_decode( $row['catname'] ),
'category_desc' => $row['description'],
'category_parent_id' => $row['parent'],
'category_count_imgs' => $row['photos'],
'category_position' => $row['catorder']
) );
$libraryClass->setLastKeyValue( $row['id'] );
}
}
/**
* Convert gallery albums
*
* @return void
*/
public function convertGalleryAlbums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id' );
foreach( $this->fetch( 'categories', 'id', array( 'cattype=?', 'a' ) ) AS $row )
{
$info = array(
'album_id' => $row['id'],
'album_owner_id' => $row['parent'],
'album_description' => $row['description'],
'album_name' => $row['catname'],
'album_type' => $row['private'] == 'yes' ? 2 : 1,
'album_count_imgs' => $row['photos'],
'album_count_comments' => $row['posts']
);
$category = $this->app->_session['more_info']['convertGalleryAlbums']['members_gallery_category'];
if ( $category == 0 )
{
$category = NULL;
}
$libraryClass->convertGalleryAlbum( $info, NULL, $category );
$libraryClass->setLastKeyValue( $row['id'] );
}
}
/**
* Convert gallery images
*
* @return void
*/
public function convertGalleryImages()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id' );
foreach( $this->fetch( 'photos', 'id' ) AS $row )
{
$info = array(
'image_id' => $row['id'],
'image_album_id' => $row['cat'],
'image_category_id' => $row['cat'],
'image_member_id' => $row['userid'],
'image_caption' => $row['title'],
'image_description' => $row['description'],
'image_views' => $row['views'],
'image_comments' => $row['numcom'],
'image_ratings_total' => $row['rating'] * $row['votes'],
'image_ratings_count' => $row['votes'],
'image_rating' => $row['rating'],
'image_date' => $row['date'],
'image_last_comment' => $row['lastpost'],
'image_ipaddress' => $row['ipaddress'],
'image_approved' => $row['approved'],
'image_file_name' => $row['bigimage']
);
$directory = $row['storecat'] ?: $row['cat'];
$path = rtrim( $this->app->_session['more_info']['convertGalleryImages']['file_location'], '/' ) . '/' . $directory . '/' . $row['bigimage'];
$libraryClass->convertGalleryImage( $info, $path );
$libraryClass->setLastKeyValue( $row['id'] );
}
}
/**
* Convert gallery comments
*
* @return void
*/
public function convertGalleryComments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id' );
foreach( $this->fetch( 'comments', 'id' ) AS $row )
{
$libraryClass->convertGalleryComment( array(
'comment_id' => $row['id'],
'comment_text' => $row['comment'],
'comment_img_id' => $row['photo'],
'comment_author_id' => $row['userid'],
'comment_author_name' => $row['username'],
'comment_ip_address' => $row['ipaddress'],
'comment_post_date' => $row['date'],
'comment_approved' => $row['approved'],
) );
$libraryClass->setLastKeyValue( $row['id'] );
}
}
/**
@@ -157,6 +157,7 @@ class _Vbulletin 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' ) );
@@ -295,13 +296,24 @@ class _Vbulletin extends \IPS\convert\Software
$filepath = rtrim( $this->app->_session['more_info']['convertGalleryImages']['file_location'], '/' ) . '/' . $filepath . '/' . $image['pictureid'] . '.picture';
}
try
{
$albumAndDate = $this->db->select( 'albumid, dateline', 'albumpicture', array( "pictureid=?", $image['pictureid'] ) )->first();
}
catch( \UnderflowException $e )
{
/* Orphaned */
$libraryClass->setLastKeyValue( $image['pictureid'] );
continue;
}
$info = array(
'image_id' => $image['pictureid'],
'image_album_id' => $this->db->select( 'albumid', 'albumpicture', array( "pictureid=?", $image['pictureid'] ) )->first(),
'image_album_id' => $albumAndDate['albumid'],
'image_member_id' => $image['userid'],
'image_caption' => $image['caption'],
'image_file_name' => $image['caption'] . '.' . $image['extension'],
'image_date' => $this->db->select( 'dateline', 'albumpicture', array( "pictureid=?", $image['pictureid'] ) )->first(),
'image_date' => $albumAndDate['dateline'],
);
$libraryClass->convertGalleryImage( $info, $filepath, $filedata );
@@ -436,7 +448,7 @@ class _Vbulletin extends \IPS\convert\Software
$data = $this->app->getLink( \IPS\Request::i()->albumid, 'gallery_albums' );
$item = \IPS\gallery\Album::load( $data );
if( $item->canView() )
if( $item->can( 'view' ) )
{
return $item->url();
}
@@ -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'] );