Version 4.6.0

This commit is contained in:
Neo committed 2025-12-19 05:55:31 -08:00
1 parent f79dcf067a
commit 517a5e1f70
2036 files changed
+110041 -26162

No files matched your search

@@ -157,7 +157,7 @@ class _Invisioncommunity extends \IPS\convert\Software
case 'core_rss_imported':
try
{
return $this->db->select( 'COUNT(*)', 'core_rss_imported', array( 'rss_imported_import_id IN(' . (string) \IPS\Db::i()->select( 'rss_import_id', 'core_rss_import', array( "rss_import_class='IPS\\forums\\Topic'" ) ) . ')' ) )->first() ;
return $this->db->select( 'COUNT(*)', 'core_rss_imported', array( 'rss_imported_import_id IN(' . (string) $this->db->select( 'rss_import_id', 'core_rss_import', array( "rss_import_class='IPS\\forums\\Topic'" ) ) . ')' ) )->first();
}
catch( \Exception $e )
{
@@ -31,7 +31,7 @@ class _Phpbb extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "phpBB (3.1.x/3.2.x)";
return "phpBB (3.1.x/3.2.x/3.3.x)";
}
/**
@@ -402,6 +402,16 @@ class _Phpbb extends \IPS\convert\Software
{
$visibility = $row['post_approved'];
}
$editName = null;
if( $row['post_edit_time'] AND $row['post_edit_user'] )
{
try
{
$editName = $this->db->select( 'username', 'users', array( 'user_id=?', $row['post_edit_user'] ) )->first();
}
catch( \UnderflowException $e ) {}
}
$info = array(
'pid' => $row['post_id'],
@@ -409,6 +419,8 @@ class _Phpbb extends \IPS\convert\Software
'post' => \IPS\convert\Software\Core\Phpbb::stripUid( $row['post_text'], $row['bbcode_uid'] ),
'append_edit' => ( $row['post_edit_user'] ) ? 1 : 0,
'edit_time' => $row['post_edit_time'],
'edit_name' => $editName,
'post_edit_reason' => $row['post_edit_reason'] ?? null,
'author_id' => $row['poster_id'],
'ip_address' => $row['poster_ip'],
'post_date' => $row['post_time'],
@@ -456,6 +468,11 @@ class _Phpbb extends \IPS\convert\Software
$libraryClass->setLastKeyValue( $row['post_id'] );
}
}
/**
* @brief temporarily store post content
*/
protected $_postContent = array();
/**
* Convert attachments
@@ -494,28 +511,32 @@ class _Phpbb extends \IPS\convert\Software
{
$pid = $this->app->getLink( $row['post_msg_id'], 'forums_posts' );
$post = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
if( !isset( $this->_postContent[ $pid ] ) )
{
$this->_postContent[ $pid ] = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
}
$attachmentName = preg_quote( $row['real_filename'], '/' );
$regex31 = '/\[attachment=(.+?)?\]\<\!\-\- ia[\d]+ \-\-\>' . $attachmentName . '\<\!\-\- ia[\d]+ \-\-\>\[\/attachment\]/i';
$regex32 = '/\<ATTACHMENT filename\="(.+?)?" index\="(.+?)?"\>\<s\>\[attachment\=(.+?)?\]\<\/s\>' . $attachmentName . '<e\>\[\/attachment\]\<\/e\>\<\/ATTACHMENT\>/i';
$changed = FALSE;
$regex31 = '/\[attachment=(\d+)?\]\<\!\-\- ia[\d]+ \-\-\>' . $attachmentName . '\<\!\-\- ia[\d]+ \-\-\>\[\/attachment\]/i';
$regex32 = '/\<ATTACHMENT filename\="(.+?)?" index\="(.+?)?"\>\<s\>\[attachment\=(\d+)?\]\<\/s\>' . $attachmentName . '<e\>\[\/attachment\]\<\/e\>\<\/ATTACHMENT\>/i';
if( preg_match( $regex31, $post ) )
$replacement = '[attachment=' . $attachId . ':name]';
if( $row['attach_comment'] )
{
$changed = TRUE;
$post = preg_replace( $regex31, '[attachment=' . $attachId . ':name]', $post );
$replacement .= '<p>' . $row['attach_comment'] . '</p>';
}
elseif( preg_match( $regex32, $post ) )
if( preg_match( $regex31, $this->_postContent[ $pid ] ) )
{
$changed = TRUE;
$post = preg_replace( $regex32, '[attachment=' . $attachId . ':name]', $post );
$this->_postContent[ $pid ] = preg_replace( $regex31, $replacement, $this->_postContent[ $pid ] );
}
if( $changed )
elseif( preg_match( $regex32, $this->_postContent[ $pid ] ) )
{
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
$this->_postContent[ $pid ] = preg_replace( $regex32, $replacement, $this->_postContent[ $pid ] );
}
else
{
$this->_postContent[ $pid ] .= '<br>' . $replacement;
}
}
catch( \UnderflowException $e ) {}
@@ -524,6 +545,12 @@ class _Phpbb extends \IPS\convert\Software
$libraryClass->setLastKeyValue( $row['attach_id'] );
}
/* Do the updates */
foreach( $this->_postContent as $pid => $content )
{
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $content ), array( 'pid=?', $pid ) );
}
}
/**
@@ -494,6 +494,7 @@ class _Smf extends \IPS\convert\Software
);
/* We need to figure out where it is */
$legacyName = null;
if ( $row['file_hash'] )
{
$location = $row['id_attach'] . '_' . $row['file_hash'];
@@ -506,6 +507,7 @@ class _Smf extends \IPS\convert\Software
$cleanName = preg_replace( array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $cleanName );
$location = $row['id_attach'] . '_' . str_replace( '.', '_', $cleanName ) . md5( $cleanName );
$legacyName = preg_replace( '~\.[\.]+~', '.', $cleanName);
}
$location = str_replace( ' ', '_', $location );
@@ -536,16 +538,31 @@ class _Smf extends \IPS\convert\Software
if ( $row['id_folder'] AND $row['id_folder'] != 1 )
{
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $location;
if( !file_exists( $path ) AND isset( $legacyName ) )
{
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $legacyName;
}
}
else
{
if ( isset( static::$paths[ $row['id_folder'] ] ) )
{
$path = rtrim( static::$paths[ $row['id_folder'] ], '/' ) . '/' . $location;
if( !file_exists( $path ) AND isset( $legacyName ) )
{
$path = rtrim( static::$paths[ $row['id_folder'] ], '/' ) . '/' . $legacyName;
}
}
else
{
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $location;
if( !file_exists( $path ) AND isset( $legacyName ) )
{
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $legacyName;
}
}
}
@@ -56,7 +56,7 @@ class _Vanilla extends \IPS\convert\Software
public static function softwareName()
{
/* Child classes must override this method */
return "Vanilla 2 (2.2.x/2.3.x)";
return "Vanilla (3.x)";
}
/**
@@ -104,10 +104,10 @@ class _Vanilla extends \IPS\convert\Software
),
'convertForumsTopics' => array(
'table' => 'Discussion',
'where' => NULL
'where' => NULL
),
'convertForumsPosts' => array(
'table' => 'Comment',
'table' => 'Discussion',
'where' => NULL,
'extra_steps' => array( 'convertForumsPosts2' )
),
@@ -305,22 +305,7 @@ class _Vanilla extends \IPS\convert\Software
*/
public static function fixPostData( $post )
{
/**
* Vanilla has a quotes plugin that seems to have changed formats quite often. - We'll try to match as many formats as we can
*/
$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 );
$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;
return \IPS\convert\Software\Core\Vanilla::fixPostData( $post );
}
/**
@@ -352,6 +337,7 @@ class _Vanilla extends \IPS\convert\Software
catch( \UnderflowException $ex )
{
$libraryClass->setLastKeyValue( $row['MediaID'] );
continue;
}
$map = array(
@@ -374,7 +360,9 @@ class _Vanilla extends \IPS\convert\Software
'attach_filesize' => $row['Size'],
);
$libraryClass->convertAttachment( $info, $map, rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . trim( $row['Path'], '/' ) );
$uploadPath = \IPS\convert\Software\Core\Vanilla::parseMediaLocation( $row['Path'], $this->app->_session['more_info']['convertAttachments']['attach_location'] );
$libraryClass->convertAttachment( $info, $map, $uploadPath );
$libraryClass->setLastKeyValue( $row['MediaID'] );
}
}
@@ -431,14 +419,37 @@ class _Vanilla extends \IPS\convert\Software
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'd.DiscussionID' );
$discussions = $this->fetch( array( 'Discussion', 'd' ), 'DiscussionID', NULL,
$discussions = $this->fetch( array( 'Discussion', 'd' ), 'DiscussionID', NULL,
'd.*, u.Name as UserName, lcu.UserID as LastCommentUserID, lcu.Name as LastCommentUserName'
);
$discussions->join( array( 'User', 'u' ), 'd.InsertUserID=u.UserID' );
$discussions->join( array( 'User', 'lcu' ), 'd.LastCommentUserID=lcu.UserID' );
foreach( $discussions AS $row )
$data = iterator_to_array( $discussions );
$this->app->preCacheLinks( $data, [ 'core_members' => 'InsertUserID', 'forums_forums' => 'CategoryID' ] );
foreach( $data AS $row )
{
/* Skip reports */
$attributes = [];
if( !empty( $row['attributes'] ) )
{
if( substr( $row['Attributes'], 0, 2 ) == 'a:' ) // Probably serialize
{
$attributes = \unserialize( $row['Attributes'] );
}
else
{
$attributes = json_decode( $row['Attributes'], TRUE );
}
}
if( isset( $attributes['Report'] ) OR $row['Type'] == 'Report' )
{
$libraryClass->setLastKeyValue( $row['DiscussionID'] );
continue;
}
$row['DateLastComment'] = 0;
$row['LastCommentUserID'] = 0;
$row['LastCommentUserName'] = '';
@@ -516,8 +527,31 @@ class _Vanilla extends \IPS\convert\Software
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'DiscussionID' );
foreach( $this->fetch( 'Discussion', 'DiscussionID' ) AS $row )
$data = iterator_to_array( $this->fetch( 'Discussion', 'DiscussionID' ) );
$this->app->preCacheLinks( $data, [ 'core_members' => 'InsertUserID', 'forums_topics' => 'DiscussionID' ] );
foreach( $data AS $row )
{
/* Skip reports */
$attributes = [];
if( !empty( $row['attributes'] ) )
{
if( substr( $row['Attributes'], 0, 2 ) == 'a:' ) // Probably serialize
{
$attributes = \unserialize( $row['Attributes'] );
}
else
{
$attributes = json_decode( $row['Attributes'], TRUE );
}
}
if( isset( $attributes['Report'] ) OR $row['Type'] == 'Report' )
{
$libraryClass->setLastKeyValue( $row['DiscussionID'] );
continue;
}
$editName = NULL;
if( $row['UpdateUserID'] )
@@ -529,6 +563,12 @@ class _Vanilla extends \IPS\convert\Software
catch( \UnderflowException $e ) {}
}
// Add Format Type (for later processing) if Markdown
if( $row['Format'] == 'Markdown' )
{
$row['Body'] = '<!--Markdown-->' . $row['Body'];
}
// First post
$info = array(
'pid' => 'fp-' . $row['DiscussionID'],
@@ -548,7 +588,9 @@ class _Vanilla extends \IPS\convert\Software
/* Reputation - Reactions are only supported if the YAGA addon was used. */
if( static::$_supportsReactions )
{
foreach( $this->db->select( '*', 'Reaction', array( "ParentType=? AND ParentID=?", 'comment', $row['DiscussionID'] ) ) AS $rep )
$reputation = iterator_to_array( $this->db->select( '*', 'Reaction', array( "ParentType=? AND ParentID=?", 'comment', $row['DiscussionID'] ) ) );
$this->app->preCacheLinks( $reputation, [ 'core_members' => [ 'InsertUserID', 'ParentAuthorID' ] ] );
foreach( $reputation AS $rep )
{
$reaction = $this->app->_session['more_info']['convertForumsPosts']['reaction_' . $rep['ActionID'] ];
@@ -577,8 +619,30 @@ class _Vanilla extends \IPS\convert\Software
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'CommentID' );
foreach( $this->fetch( 'Comment', 'CommentID' ) AS $row )
$data = iterator_to_array( $this->fetch( 'Comment', 'CommentID' ) );
$this->app->preCacheLinks( $data, [ 'core_members' => 'InsertUserID', 'forums_topics' => 'DiscussionID' ] );
foreach( $data AS $row )
{
/* Check whether this is a report */
if( !empty( $row['Attributes'] ) )
{
if( substr( $row['Attributes'], 0, 2 ) == 'a:' ) // Probably serialize
{
$attributes = \unserialize( $row['Attributes'] );
}
else
{
$attributes = json_decode( $row['Attributes'], TRUE );
}
if( !empty( $attributes['Type'] ) AND $attributes['Type'] == 'Report' )
{
$libraryClass->setLastKeyValue( $row['CommentID'] );
continue;
}
}
$editName = NULL;
if( $row['UpdateUserID'] )
@@ -590,6 +654,12 @@ class _Vanilla extends \IPS\convert\Software
catch( \UnderflowException $e ) {}
}
// Add Format Type (for later processing) if Markdown
if( $row['Format'] == 'Markdown' )
{
$row['Body'] = '<!--Markdown-->' . $row['Body'];
}
$info = [
'pid' => $row['CommentID'],
'topic_id' => $row['DiscussionID'],
@@ -0,0 +1,530 @@
<?php
/**
* @brief Converter wpForo Forum Class
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @package Invision Community
* @subpackage convert
* @since 24 Jan 2021
*/
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;
}
/**
* wpForo Forums Converter
*/
class _Wpforo extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "wpForo (1.9.x)";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "wpforo";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return [
'convertForumsForums' => [
'table' => 'wpforo_forums',
'where' => NULL
],
'convertForumsTopics' => [
'table' => 'wpforo_topics',
'where' => NULL
],
'convertForumsPosts' => [
'table' => 'wpforo_posts',
'where' => NULL
],
'convertAttachments' => [
'table' => 'wpforo_posts',
'where' => NULL
]
];
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'wpforo' ) );
}
/**
* 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 ), 4, 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( 'convert', 'RebuildFirstPostIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
\IPS\Task::queue( 'convert', 'DeleteEmptyTopics', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
/* Rebuild Leaderboard */
\IPS\Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
\IPS\Db::i()->delete( 'core_reputation_leaderboard_history' );
/* Caches */
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'forums_topics', 'class' => 'IPS\forums\Topic' ), 3, array( 'app', 'link', 'class' ) );
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 Post
* @return string Fixed Post
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\Wpforo::fixPostData( $post );
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertForumsPosts'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = [];
switch( $method )
{
case 'convertForumsPosts':
/* Get our reactions to let the admin map them */
$options = [];
$descriptions = [];
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'] = [
'rep_positive' => [
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => NULL,
'field_required' => TRUE,
'field_extra' => [ 'parse' => 'image', 'options' => $options, 'descriptions' => $descriptions, 'gridspan' => 2 ],
'field_hint' => NULL,
'field_validation' => NULL,
],
];
break;
}
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : [];
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'forumid' );
foreach( $this->fetch( 'wpforo_forums', 'forumid' ) AS $row )
{
$info = [
'id' => $row['forumid'],
'name' => $row['title'],
'description' => $row['description'],
'topics' => $row['topics'],
'posts' => $row['posts'],
'parent_id' => ( !$row['parentid'] OR $row['parentid'] == $row['forumid'] ) ? -1 : $row['parentid'],
'position' => $row['order'],
'sub_can_post' => ( !$row['parentid'] OR $row['is_cat'] ) ? 0 : 1,
'feature_color' => $row['color']
];
$forumId = $libraryClass->convertForumsForum( $info );
if( $forumId !== FALSE )
{
$this->app->addLink( $forumId, $row['slug'], 'forum_furl' );
/* Followers */
foreach ( $this->db->select( '*', 'wpforo_subscribes', [ 'itemid=? AND type=?', $row['forumid'], 'forum' ] ) as $follow )
{
$libraryClass->convertFollow( [
'follow_app' => 'forums',
'follow_area' => 'forum',
'follow_rel_id' => $row['forumid'],
'follow_rel_id_type' => 'forums_forums',
'follow_member_id' => $follow['userid'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => $follow['active'],
'follow_notify_meta' => '',
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
] );
}
}
$libraryClass->setLastKeyValue( $row['forumid'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'topicid' );
foreach( $this->fetch( 'wpforo_topics', 'topicid' ) AS $row )
{
$info = [
'tid' => $row['topicid'],
'title' => $row['title'],
'forum_id' => $row['forumid'],
'state' => ( $row['closed'] == 1 ) ? 'closed' : 'open',
'starter_id' => $row['userid'],
'start_date' => \strtotime( $row['created'] ),
'posts' => $row['posts'],
'views' => $row['views'],
'approved' => $row['private'] ? 0 : 1
];
$topicId = $libraryClass->convertForumsTopic( $info );
if( $topicId !== FALSE )
{
$this->app->addLink( $topicId, $row['slug'], 'topic_furl' );
/* Tags */
$tags = explode( ',', $row['tags'] );
foreach( $tags as $text )
{
$libraryClass->convertTag( [
'tag_meta_app' => 'forums',
'tag_meta_area' => 'forums',
'tag_meta_parent_id' => $row['forumid'],
'tag_meta_id' => $row['topicid'],
'tag_text' => $text,
'tag_member_id' => $row['userid'],
] );
}
/* Follows */
foreach( $this->db->select( '*', 'wpforo_subscribes', [ 'itemid=? AND type=?', $row['topicid'], 'topic' ] ) AS $follow )
{
$libraryClass->convertFollow( [
'follow_app' => 'forums',
'follow_area' => 'topic',
'follow_rel_id' => $row['topicid'],
'follow_rel_id_type' => 'forums_topics',
'follow_member_id' => $follow['userid'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => $follow['active'],
'follow_notify_meta' => '',
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
] );
}
}
$libraryClass->setLastKeyValue( $row['topicid'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'postid' );
foreach( $this->fetch( 'wpforo_posts', 'postid' ) AS $row )
{
$info = [
'pid' => $row['postid'],
'topic_id' => $row['topicid'],
'post' => $row['body'],
'edit_time' => $row['modified'] != $row['created'] ? \strtotime( $row['modified'] ) : null,
'author_id' => $row['userid'],
'post_date' => \strtotime( $row['created'] ),
'queued' => $row['private'] ? 1 : 0,
];
$libraryClass->convertForumsPost( $info );
/* Reputation */
foreach( $this->db->select( '*', 'wpforo_likes', [ 'postid=?', $row['postid'] ] ) AS $rep )
{
$libraryClass->convertReputation( [
'id' => $rep['likeid'],
'app' => 'forums',
'type' => 'pid',
'type_id' => $row['postid'],
'member_id' => $rep['userid'],
'member_received' => $rep['post_userid'],
'rep_date' => $info['post_date'],
'reaction' => $this->app->_session['more_info']['convertForumsPosts']['rep_positive']
] );
}
$libraryClass->setLastKeyValue( $row['postid'] );
}
}
/**
* @brief temporarily store post content
*/
protected $_postContent = [];
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'postid' );
foreach( $this->fetch( 'wpforo_posts', 'postid' ) AS $row )
{
if( !\stristr( $row['body'], '[attach]' ) AND !\stristr( $row['body'], 'wpforo-attached-file' ) )
{
$libraryClass->setLastKeyValue( $row['postid'] );
continue;
}
$map = [
'id1' => $row['topicid'],
'id2' => $row['postid']
];
/* Advanced Attachments */
$matches = [];
preg_match_all( '/\[attach\](\d+)\[\/attach\]/i', $row['body'], $matches );
if( \count( $matches ) )
{
foreach( $matches[1] as $key => $id )
{
$sourceAttachment = $this->db->select( '*', 'wpforo_attachments', [ 'attachid=?', $id ] )->first();
$url = explode( '/', $sourceAttachment['fileurl'] );
$filename = array_pop( $url );
$info = [
'attach_id' => $row['postid'],
'attach_file' => $sourceAttachment['filename'],
'attach_date' => \strtotime( $row['created'] ),
'attach_member_id' => $sourceAttachment['userid'],
'attach_filesize' => $sourceAttachment['size'],
];
$realFilePath = '/wpforo/attachments/' . $sourceAttachment['userid'] . '/' . $filename;
$path = rtrim( $this->app->_parent->_session['more_info']['convertMembers']['wpuploads'], '/' ) . $realFilePath;
$attachId = $libraryClass->convertAttachment( $info, $map, $path );
/* Update post if we can */
try
{
if ( $attachId !== FALSE )
{
$pid = $this->app->getLink( $row['postid'], 'forums_posts' );
if( !isset( $this->_postContent[ $pid ] ) )
{
$this->_postContent[ $pid ] = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
}
$this->_postContent[ $pid ] = str_replace( $matches[0][ $key ], '[attachment=' . $attachId . ':name]', $this->_postContent[ $pid ] );
}
}
catch( \UnderflowException $e ) {}
catch( \OutOfRangeException $e ) {}
}
}
/* Default Attachments */
$matches = [];
preg_match_all( '/\<div id\="wpfa\-[\d]+"(.+?)?>\<a class\="wpforo\-default\-attachment" href\="(.+?)"(.+?)?>\<i class\="(.+?)">\<\/i>(.+?)<\/a><\/div>/i', $row['body'], $matches );
if( \count( $matches ) )
{
foreach( $matches[2] as $key => $url )
{
$url = explode( '/', $url );
$filename = array_pop( $url );
$info = [
'attach_id' => $row['postid'],
'attach_file' => $filename,
'attach_date' => \strtotime( $row['created'] ),
'attach_member_id' => $row['userid'],
];
$realFilePath = '/wpforo/default_attachments/' . $filename;
$path = rtrim( $this->app->_parent->_session['more_info']['convertMembers']['wpuploads'], '/' ) . $realFilePath;
$attachId = $libraryClass->convertAttachment( $info, $map, $path );
/* Update post if we can */
try
{
if ( $attachId !== FALSE )
{
$pid = $this->app->getLink( $row['postid'], 'forums_posts' );
if( !isset( $this->_postContent[ $pid ] ) )
{
$this->_postContent[ $pid ] = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
}
$this->_postContent[ $pid ] = str_replace( $matches[0][ $key ], '[attachment=' . $attachId . ':name]', $this->_postContent[ $pid ] );
}
}
catch( \UnderflowException $e ) {}
catch( \OutOfRangeException $e ) {}
}
}
$libraryClass->setLastKeyValue( $row['postid'] );
}
/* Do the updates */
foreach( $this->_postContent as $id => $content )
{
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $content ), array( 'pid=?', $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();
$wpForoSlug = \defined('WPFORO_SLUG') ? WPFOROSLUG : 'community';
$matches = [];
if( preg_match( '#/' . $wpForoSlug . '/([a-z0-9-]+)/([a-z0-9-]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$class = '\IPS\forums\Topic';
$types = [ 'topic_furl' ];
$oldId = $matches[2];
}
elseif( preg_match( '#/' . $wpForoSlug . '/([a-z0-9-]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$class = '\IPS\forums\Forum';
$types = [ 'forum_furl' ];
$oldId = $matches[1];
}
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;
}
}