Version 4.1.19.4

This commit is contained in:
Neo committed 2025-12-19 05:42:01 -08:00
1 parent 2bd5025018
commit 0dc2aee5ed
312 files changed
+53730 -32118

No files matched your search

@@ -0,0 +1,219 @@
<?php
/**
* @brief Converter BBPress Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 21 Nov 2016
*/
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 _Bbpress extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "BBPress (for WordPress)";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "bbpress";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'posts',
'where' => array( 'post_type=?', 'forum' ),
),
'convertForumsTopics' => array(
'table' => 'posts',
'where' => array( 'post_type=?', 'topic' ),
),
'convertForumsPosts' => array(
'table' => 'posts',
'where' => array( '(post_type=? OR post_type=?)', 'topic', 'reply' ),
)
);
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'wordpress' ) );
}
/**
* 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( '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 ), 4, array( 'app' ) );
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics" );
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'ID' );
foreach( $this->fetch( 'posts', 'ID', array( 'post_type=?', 'forum' ) ) AS $row )
{
$info = array(
'id' => $row['ID'],
'name' => $row['post_title'],
'description' => $row['post_content'],
'parent_id' => $row['post_parent'],
);
$libraryClass->convertForumsForum( $info );
$libraryClass->setLastKeyValue( $row['ID'] );
}
}
/**
* User cache to minimise repeated DB lookups
*
* @var array $userCache
*/
protected static $userCache = array();
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'ID' );
/* Which username type? */
$userName = $this->app->_parent->_session['more_info']['convertMembers']['username'] == 'username' ? 'user_login' : 'display_name';
foreach( $this->fetch( 'posts', 'ID', array( 'post_type=?', 'topic' ) ) AS $row )
{
if( !isset( static::$userCache[ $row['post_author'] ] ) )
{
try
{
static::$userCache[ $row['post_author'] ] = $this->db->select( $userName, 'users', array( 'ID=?', $row['post_author'] ) )->first();
}
catch( \UnderflowException $e )
{
static::$userCache[ $row['post_author'] ] = 'Guest';
}
}
$info = array(
'tid' => $row['ID'],
'title' => $row['post_title'],
'forum_id' => $row['post_parent'],
'state' => ( $row['post_status'] == 'publish' ) ? 'open' : 'closed',
'starter_id' => $row['post_author'],
'start_date' => \strtotime( $row['post_date'] ),
'starter_name' => static::$userCache[ $row['post_author'] ],
);
$libraryClass->convertForumsTopic( $info );
$libraryClass->setLastKeyValue( $row['ID'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'ID' );
/* Which username type? */
$userName = $this->app->_parent->_session['more_info']['convertMembers']['username'] == 'username' ? 'user_login' : 'display_name';
foreach( $this->fetch( 'posts', 'ID', array( '(post_type=? OR post_type=?)', 'topic', 'reply' ) ) AS $row )
{
if( !isset( static::$userCache[ $row['post_author'] ] ) )
{
try
{
static::$userCache[ $row['post_author'] ] = $this->db->select( $userName, 'users', array( 'ID=?', $row['post_author'] ) )->first();
}
catch( \UnderflowException $e )
{
static::$userCache[ $row['post_author'] ] = 'Guest';
}
}
$info = array(
'pid' => $row['ID'],
'topic_id' => $row['post_type'] == 'topic' ? $row['ID'] : $row['post_parent'],
'post' => $row['post_content'],
'author_id' => $row['post_author'],
'author_name' => static::$userCache[ $row['post_author'] ],
'post_date' => \strtotime( $row['post_date'] )
);
$libraryClass->convertForumsPost( $info );
$libraryClass->setLastKeyValue( $row['ID'] );
}
}
}
@@ -0,0 +1,498 @@
<?php
/**
* @brief Converter ExpressionEngine Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 17 June 2016
*/
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 _Expressionengine extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "ExpressionEngine";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "expressionengine";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'exp_forums',
'where' => NULL
),
'convertForumsTopics' => array(
'table' => 'exp_forum_topics',
'where' => NULL
),
'convertForumsPosts' => array(
'table' => 'exp_forum_topics',
'where' => NULL,
'extra_steps' => array( 'convertOtherPosts' )
),
'convertOtherPosts' => array(
'table' => 'exp_forum_posts',
'where' => NULL,
),
'convertAttachments' => array(
'table' => 'expForumAttachments',
'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( 'expressionengine' ) );
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertAttachments'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertAttachments':
$return['convertAttachments'] = array(
'attach_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_ee_forum_at_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 string Message 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( '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 ), 4, array( 'app' ) );
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics" );
}
/**
* Fix post data
*
* @param string raw post data
* @return string parsed post data
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\Expressionengine::fixPostData( $post );
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'forum_id' );
foreach( $this->fetch( 'exp_forums', 'forum_id' ) AS $row )
{
$info = array(
'id' => $row['forum_id'],
'name' => $row['forum_name'],
'description' => $row['forum_description'],
'topics' => $row['forum_total_topics'],
'posts' => $row['forum_total_posts'],
'last_post' => $row['forum_last_post_date'],
'last_poster_id' => $row['forum_last_post_author_id'],
'last_poster_name' => $row['forum_last_post_author'],
'parent_id' => ( $row['forum_parent'] == 0 ) ? -1 : $row['forum_parent'],
'position' => $row['forum_order'],
'last_title' => $row['forum_last_post_title'],
'allow_poll' => 1,
'inc_postcount' => 1,
'sub_can_post' => 1,
);
$libraryClass->convertForumsForum( $info );
$libraryClass->setLastKeyValue( $row['forum_id'] );
}
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'topic_id' );
foreach( $this->fetch( 'exp_forum_topics', 'topic_id' )->join( 'exp_members', 'exp_members.member_id = exp_forum_topics.author_id' ) AS $row )
{
/* Poll */
$poll = NULL;
if( $row['poll'] == 'y' )
{
$choices = array();
$votes = array();
$index = 1;
$pollData = $this->db->select( '*', 'exp_forum_polls', array( 'topic_id=?', $row['topic_id'] ) )->first();
foreach( \unserialize( $pollData['poll_answers'] ) as $value )
{
$choices[ $index ] = $value['answer'];
$votes[ $index ] = $value['votes'];
$index++;
}
$poll['poll_data'] = array(
'pid' => $pollData['poll_id'],
'choices' => array(
1 => array(
'question' => $pollData['poll_question'],
'multi' => 0,
'choice' => $choices,
'votes' => $votes
)
),
'poll_question' => $pollData['poll_question'],
'start_date' => $pollData['poll_date'],
'starter_id' => $pollData['author_id'],
'votes' => array_sum( $votes ),
'poll_view_voters' => 0
);
$poll['vote_data'] = array();
$ourVotes = array();
foreach( $this->db->select( '*', 'exp_forum_pollvotes', array( "poll_id=?", $pollData['poll_id'] ) ) AS $vote )
{
if ( !isset( $ourVotes[ $vote['member_id'] ] ) )
{
$ourVotes[ $vote['member_id'] ] = array( 'votes' => array() );
}
$ourVotes[ $vote['member_id'] ]['votes'][] = ( $vote['choice_id'] + 1 );
$ourVotes[ $vote['member_id'] ]['member_id'] = $vote['member_id'];
}
foreach( $ourVotes AS $memberId => $vote )
{
$poll['vote_data'][ $memberId ] = array(
'member_id' => $vote['member_id'],
'member_choices' => array( 1 => $vote['votes'] ),
);
}
}
$lastPoster = NULL;
try
{
if( $row['last_post_author_id'] )
{
$lastPoster = $this->db->select( 'screen_name', 'exp_members', array( 'member_id=?', $row['last_post_author_id'] ) )->first();
}
}
catch( \UnderflowException $e ) { }
$info = array(
'tid' => $row['topic_id'],
'title' => $row['title'],
'forum_id' => $row['forum_id'],
'state' => ( $row['status'] == 'o' ) ? 'open' : 'closed',
'posts' => $row['thread_total'],
'starter_id' => $row['author_id'],
'start_date' => $row['topic_date'],
'last_poster_id' => $row['last_post_author_id'],
'last_post' => $row['last_post_date'],
'starter_name' => $row['screen_name'],
'last_poster_name' => $lastPoster,
'poll_state' => $poll,
'views' => $row['thread_views'],
'approved' => 1,
'pinned' => ( $row['sticky'] == 'y' ) ? 1 : 0
);
$libraryClass->convertForumsTopic( $info );
$libraryClass->setLastKeyValue( $row['topic_id'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'topic_id' );
foreach( $this->fetch( 'exp_forum_topics', 'topic_id', NULL, 'exp_forum_topics.*, exp_members.screen_name' )
->join( 'exp_members', 'exp_members.member_id = exp_forum_topics.author_id' ) AS $row )
{
$editName = NULL;
try
{
if( $row['topic_edit_date'] )
{
$editName = $this->db->select( 'screen_name', 'exp_members', array( 'member_id=?', $row['topic_edit_author'] ) )->first();
}
}
catch( \UnderflowException $e ) { }
$info = array(
'pid' => 't' . $row['topic_id'],
'topic_id' => $row['topic_id'],
'post' => $this->fixPostData( $row['body'] ),
'edit_time' => $row['topic_edit_date'],
'edit_name' => $editName,
'author_id' => $row['author_id'],
'author_name' => $row['screen_name'],
'ip_address' => $row['ip_address'],
'post_date' => $row['topic_date'],
'queued' => 0
);
$libraryClass->convertForumsPost( $info );
$libraryClass->setLastKeyValue( $row['topic_id'] );
}
}
/**
* Convert other posts
*
* @return void
*/
public function convertOtherPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'post_id' );
foreach( $this->fetch( 'exp_forum_posts', 'post_id', NULL, 'exp_forum_posts.*, exp_members.screen_name' )
->join( 'exp_members', 'exp_members.member_id = exp_forum_posts.author_id' ) AS $row )
{
$editName = NULL;
try
{
if( $row['post_edit_date'] )
{
$editName = $this->db->select( 'screen_name', 'exp_members', array( 'member_id=?', $row['post_edit_author'] ) )->first();
}
}
catch( \UnderflowException $e ) { }
$info = array(
'pid' => $row['post_id'],
'topic_id' => $row['topic_id'],
'post' => $this->fixPostData( $row['body'] ),
'edit_time' => $row['post_edit_date'],
'edit_name' => $editName,
'author_id' => $row['author_id'],
'author_name' => $row['screen_name'],
'ip_address' => $row['ip_address'],
'post_date' => $row['post_date'],
'queued' => 0
);
$libraryClass->convertForumsPost( $info );
$libraryClass->setLastKeyValue( $row['post_id'] );
}
}
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'attachment_id' );
$it = $this->fetch( 'exp_forum_attachments', 'attachment_id' );
foreach( $it AS $row )
{
$map = array(
'id1' => $row['topic_id'],
'id2' => $row['post_id'],
);
$info = array(
'attach_id' => $row['attachment_id'],
'attach_file' => $row['filename'],
'attach_date' => $row['attachment_date'],
'attach_member_id' => $row['member_id'],
'attach_hits' => $row['hits'],
'attach_ext' => \strtolower( trim( $row['extension'], '.' ) ),
'attach_filesize' => ( $row['filesize'] * 1000 ), //convert to kb
);
$realName = $row['filehash'] . $row['extension'];
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $realName;
$libraryClass->convertAttachment( $info, $map, $path );
$libraryClass->setLastKeyValue( $row['attachment_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( '#/(viewforum|viewthread|viewreply)/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
switch( $matches[1] )
{
case 'viewforum':
$class = '\IPS\forums\Forum';
$types = array( 'forums', 'forums_forums' );
break;
case 'viewthread':
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
break;
case 'viewreply':
$class = '\IPS\forums\Topic\Post';
$types = array( 'posts', 'forums_posts' );
break;
}
/* Sanity check - we found one right? */
if( !isset( $class ) )
{
return NULL;
}
try
{
try
{
$data = (string) $this->app->getLink( (int) $matches[2], $types );
}
catch( \OutOfRangeException $e )
{
$data = (string) $this->app->getLink( (int) $matches[2], $types, FALSE, TRUE );
}
$item = $class::load( $data );
if( $item instanceof \IPS\Content\Item )
{
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;
}
}
@@ -0,0 +1,585 @@
<?php
/**
* @brief Converter MyBB Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 21 Jan 2015
*/
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 _Mybb extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "MyBB 1.8.x";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "mybb";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'forums',
'where' => NULL
),
'convertForumsTopics' => array(
'table' => 'threads',
'where' => NULL
),
'convertForumsPosts' => array(
'table' => 'posts',
'where' => NULL
),
'convertAttachments' => array(
'table' => 'attachments',
'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( 'mybb' ) );
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertAttachments'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertAttachments':
$return['convertAttachments'] = array(
'attach_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_mybb_attach_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( '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( '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' ) );
/* 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" );
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'fid' );
foreach( $this->fetch( 'forums', 'fid' ) AS $row )
{
$info = array(
'id' => $row['fid'],
'name' => $row['name'],
'description' => $row['description'],
'topics' => $row['threads'],
'posts' => $row['posts'],
'last_post' => $row['lastpost'],
'last_poster_id' => $row['lastposteruid'],
'last_poster_name' => $row['lastposter'],
'parent_id' => $row['pid'] ?: -1,
'position' => $row['disporder'],
'password' => $row['password'] ?: NULL,
'last_title' => $row['lastpostsubject'],
'inc_postcount' => $row['usepostcounts'],
'redirect_url' => $row['linkto'],
'sub_can_post' => ( $row['type'] == 'c' ) ? 0 : 1,
'queued_topics' => $row['unapprovedthreads'],
'queued_posts' => $row['unapprovedposts'],
'forum_allow_rating' => $row['allowtratings'],
);
$libraryClass->convertForumsForum( $info );
/* Followers */
foreach( $this->db->select( '*', 'forumsubscriptions', array( "fid=?", $row['fid'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'forum',
'follow_rel_id' => $row['fid'],
'follow_rel_id_type' => 'forums_forums',
'follow_member_id' => $follow['uid'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'follow_notify_meta' => '',
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
$libraryClass->setLastKeyValue( $row['fid'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'tid' );
foreach( $this->fetch( 'threads', 'tid' ) AS $row )
{
/* Poll */
$poll = NULL;
if ( $row['poll'] > 0 )
{
try
{
$pollData = $this->db->select( '*', 'polls', array( "pid=?", $row['poll'] ) )->first();
$choices = array();
$index = 1;
foreach( explode( '||~|~||', $pollData['options'] ) AS $choice )
{
$choices[$index] = trim( $choice );
$index++;
}
/* Reset Index */
$index = 1;
$votes = array();
$numvotes = 0;
foreach( explode( '||~|~||', $pollData['votes'] ) AS $vote )
{
$count = $this->db->select( 'COUNT(*)', 'pollvotes', array( "pid=? AND voteoption=?", $row['poll'], $index ) )->first();
$votes[$index] = $count;
$index++;
$numvotes += $count;
}
$poll = array();
$poll['poll_data'] = array(
'pid' => $pollData['pid'],
'choices' => array( 1 => array(
'question' => $pollData['question'],
'multi' => $pollData['multiple'],
'choice' => $choices,
'votes' => $votes
) ),
'poll_question' => $pollData['question'],
'start_date' => $pollData['dateline'],
'starter_id' => $row['uid'],
'votes' => $numvotes,
'poll_view_voters' => $pollData['public']
);
$poll['vote_data'] = array();
$ourVotes = array();
foreach( $this->db->select( '*', 'pollvotes', array( "pid=?", $pollData['pid'] ) ) AS $vote )
{
if ( !isset( $ourVotes[$vote['uid']] ) )
{
/* Create our structure - vB stores each individual vote as a different row whereas we combine them per user */
$ourVotes[$vote['uid']] = array( 'votes' => array() );
}
$ourVotes[$vote['uid']]['votes'][] = $vote['voteoption'];
/* These don't matter - just use the latest one */
$ourVotes[$vote['uid']]['vid'] = $vote['vid'];
$ourVotes[$vote['uid']]['vote_date'] = $vote['dateline'];
$ourVotes[$vote['uid']]['member_id'] = $vote['uid'];
}
/* Now we need to re-wrap it all for storage */
foreach( $ourVotes AS $member_id => $vote )
{
$poll['vote_data'][$member_id] = array(
'vid' => $vote['vid'],
'vote_date' => $vote['vote_date'],
'member_id' => $vote['member_id'],
'member_choices' => array( 1 => $vote['votes'] ),
);
}
}
catch( \UnderflowException $e ) {} # if the poll is missing, don't bother
}
/* Moved ?*/
$moved = explode( "|", $row['closed'] );
$moved_to = NULL;
if ( isset( $moved[0] ) AND $moved[0] == 'moved' )
{
try
{
$moved_to = array(
$moved[1],
$this->db->select( 'fid', 'threads', array( "tid=?", $moved[1] ) )->first()
);
}
catch( \UnderflowException $e )
{
$moved_to = NULL;
}
}
$info = array(
'tid' => $row['tid'],
'title' => $row['subject'],
'forum_id' => $row['fid'],
'state' => ( $row['closed'] == 1 ) ? 'closed' : 'open',
'starter_id' => $row['uid'],
'start_date' => $row['dateline'],
'last_poster_id' => $row['lastposteruid'],
'last_post' => $row['lastpost'],
'starter_name' => $row['username'],
'last_poster_name' => $row['lastposter'],
'poll_state' => $poll,
'views' => $row['views'],
'approved' => $row['visible'], # it's handled exactly the same
'pinned' => $row['sticky'],
'moved_to' => $moved_to,
'topic_queuedposts' => $row['unapprovedposts'],
'topic_rating_total' => $row['totalratings'],
'topic_rating_hits' => $row['numratings'],
'topic_hiddenposts' => $row['deletedposts']
);
$libraryClass->convertForumsTopic( $info );
/* If we have a prefix, convert it */
if ( $row['prefix'] > 0 )
{
try
{
$prefix = $this->db->select( 'prefix', 'threadprefixes', array( "pid=?", $row['prefix'] ) )->first();
$libraryClass->convertTag( array(
'tag_meta_app' => 'forums',
'tag_meta_area' => 'forums',
'tag_meta_parent_id' => $row['fid'],
'tag_meta_id' => $row['tid'],
'tag_text' => $prefix,
'tag_member_id' => $row['uid'],
'tag_prefix' => 1,
) );
}
catch( \UnderflowException $e ) {}
}
/* Follows */
foreach( $this->db->select( '*', 'threadsubscriptions', array( "tid=?", $row['tid'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'topic',
'follow_rel_id' => $row['tid'],
'follow_rel_id_type' => 'forums_topics',
'follow_member_id' => $follow['uid'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'follow_notify_meta' => '',
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
/* Ratings */
foreach( $this->db->select( '*', 'threadratings', array( "tid=?", $row['tid'] ) ) AS $rating )
{
$libraryClass->convertRating( array(
'id' => $rating['rid'],
'class' => 'IPS\\forums\\Topic',
'item_link' => 'forums_topics',
'item_id' => $rating['tid'],
'ip' => $rating['ipaddress'],
'rating' => $rating['rating'],
'member' => $rating['uid']
) );
}
$libraryClass->setLastKeyValue( $row['tid'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'pid' );
foreach( $this->fetch( 'posts', 'pid' ) AS $row )
{
switch( $row['visible'] )
{
case 1:
$queued = 0;
break;
case 0:
$queued = 1;
break;
case -1:
$queued = -1;
break;
}
$info = array(
'pid' => $row['pid'],
'topic_id' => $row['tid'],
'post' => $row['message'],
'edit_time' => $row['edittime'],
'author_id' => $row['uid'],
'author_name' => $row['username'],
'ip_address' => $row['ipaddress'],
'post_date' => $row['dateline'],
'queued' => $queued,
'post_edit_reason' => $row['editreason'],
);
$libraryClass->convertForumsPost( $info );
/* Reputation */
foreach( $this->db->select( '*', 'reputation', array( "pid=?", $row['pid'] ) ) AS $rep )
{
$libraryClass->convertReputation( array(
'id' => $rep['rid'],
'app' => 'forums',
'type' => 'pid',
'type_id' => $row['pid'],
'member_id' => $rep['adduid'],
'member_received' => $rep['uid'],
'rep_date' => $rep['dateline'],
'rep_rating' => $rep['reputation']
) );
}
/* Warnings */
foreach( $this->db->select( '*', 'warnings', array( "pid=?", $row['pid'] ) ) AS $warn )
{
$libraryClass->convertWarnLog( array(
'wl_id' => $warn['wid'],
'wl_member' => $warn['uid'],
'wl_moderator' => $warn['issuedby'],
'wl_date' => $warn['dateline'],
'wl_points' => $warn['points'],
'wl_note_mods' => $warn['notes'],
) );
}
$libraryClass->setLastKeyValue( $row['pid'] );
}
}
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'aid' );
foreach( $this->fetch( 'attachments', 'aid' ) AS $row )
{
try
{
$topic_id = $this->db->select( 'tid', 'posts', array( "pid=?", $row['pid'] ) )->first();
}
catch( \UnderflowException $e )
{
/* Post is orphaned */
$libraryClass->setLastKeyValue( $row['aid'] );
continue;
}
$map = array(
'id1' => $topic_id,
'id2' => $row['pid'],
);
$ext = explode( '.', $row['filename'] );
$ext = array_pop( $ext );
$info = array(
'attach_id' => $row['aid'],
'attach_file' => $row['filename'],
'attach_date' => $row['dateuploaded'],
'attach_member_id' => $row['uid'],
'attach_hits' => $row['downloads'],
'attach_ext' => $ext,
'attach_filesize' => $row['filesize'],
);
$libraryClass->convertAttachment( $info, $map, rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $row['attachname'] );
$libraryClass->setLastKeyValue( $row['aid'] );
}
}
/**
* 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( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'showthread.php' ) !== FALSE )
{
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
$oldId = \IPS\Request::i()->tid;
}
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'forumdisplay.php' ) !== FALSE )
{
$class = '\IPS\forums\Forum';
$types = array( 'forums', 'forums_forums' );
$oldId = \IPS\Request::i()->fid;
}
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\Item )
{
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;
}
}
@@ -0,0 +1,549 @@
<?php
/**
* @brief Converter phpBB Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 21 Jan 2015
*/
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 _Phpbb extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "phpBB 3.x";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "phpbb";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'forums',
'where' => NULL,
),
'convertForumsTopics' => array(
'table' => 'topics',
'where' => NULL
),
'convertForumsPosts' => array(
'table' => 'posts',
'where' => NULL
),
'convertAttachments' => array(
'table' => 'attachments',
'where' => NULL
)
);
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertForumsForums',
'convertAttachments'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertForumsForums':
$return['convertForumsForums'] = array();
$forums = $this->db->select( '*', 'forums' );
foreach( $forums AS $forum )
{
if ( $forum['forum_password'] )
{
\IPS\Member::loggedIn()->language()->words["forum_password_{$forum['forum_id']}"] = \IPS\Member::loggedIn()->language()->addToStack( 'forum_password', FALSE, array( 'sprintf' => array( $forum['forum_name'] ) ) );
\IPS\Member::loggedIn()->language()->words["forum_password_{$forum['forum_id']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'forum_password_desc' );
$return['convertForumsForums']["forum_password_{$forum['forum_id']}"] = array(
'field_class' => 'IPS\\Helpers\\Form\\Text',
'field_default' => NULL,
'field_required' => FALSE,
'field_extra' => array(),
'field_hint' => NULL,
);
}
}
break;
case 'convertAttachments':
$return['convertAttachments'] = array(
'attach_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_phpbb_attach_path'),
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
),
);
break;
}
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'phpbb' ) );
}
/**
* 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( '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 ), 4, array( 'app' ) );
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics" );
}
/**
* Fix post data
*
* @param string raw post data
* @return string parsed post data
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\Phpbb::fixPostData( $post );
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'forum_id' );
foreach( $this->fetch( 'forums', 'forum_id' ) AS $row )
{
$info = array(
'id' => $row['forum_id'],
'name' => $row['forum_name'],
'description' => $row['forum_desc'],
'topics' => isset( $row['forum_topics_approved'] ) ? $row['forum_topics_approved'] : $row['forum_topics'],
'posts' => isset( $row['forum_posts_approved'] ) ? $row['forum_posts_approved'] : $row['forum_posts'],
'last_post' => $row['forum_last_post_time'],
'last_poster_id' => $row['forum_last_poster_id'],
'last_poster_name' => $row['forum_last_poster_name'],
'parent_id' => ( $row['parent_id'] != 0 ) ? $row['parent_id'] : -1,
'conv_parent' => ( $row['parent_id'] != 0 ) ? $row['parent_id'] : -1,
'position' => $row['left_id'],
'password' => ( isset( $this->app->_session['more_info']['convertForumsForums']["forum_password_{$row['forum_id']}"] ) ) ? $this->app->_session['more_info']['convertForumsForums']["forum_password_{$row['forum_id']}"] : NULL,
'last_title' => $row['forum_last_post_subject'],
'queued_topics' => isset( $row['forum_topics_unapproved'] ) ? $row['forum_topics_unapproved'] : 0,
'queued_posts' => isset( $row['forum_posts_unapproved'] ) ? $row['forum_topics_unapproved'] : 0,
'sub_can_post' => ( $row['forum_type'] == 1 ) ? TRUE : FALSE
);
$libraryClass->convertForumsForum( $info );
/* Follows */
foreach( $this->db->select( '*', 'forums_watch', array( "forum_id=?", $row['forum_id'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'forum',
'follow_rel_id' => $row['forum_id'],
'follow_rel_id_type' => 'forums_forums',
'follow_member_id' => $follow['user_id'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'follow_notify_meta' => '',
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
$libraryClass->setLastKeyValue( $row['forum_id'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'topic_id' );
foreach( $this->fetch( 'topics', 'topic_id' ) AS $row )
{
$poll = NULL;
if ( $row['poll_title'] )
{
$poll = array();
$choices = array();
$votes = array();
$index = 1;
$search = array(); # make sure we actually assign the vote correctly
foreach( $this->db->select( '*', 'poll_options', array( "topic_id=?", $row['topic_id'] ) ) AS $choice )
{
$choices[$index] = $choice['poll_option_text'];
$votes[$index] = $choice['poll_option_total'];
$search[$index] = $choice['poll_option_id'];
$index++;
}
$poll['poll_data'] = array(
'pid' => $row['topic_id'],
'choices' => array( 1 => array(
'question' => $row['poll_title'],
'multi' => ( $row['poll_max_options'] > 1 ) ? 1 : 0,
'choice' => $choices,
'votes' => $votes,
) ),
'poll_question' => $row['poll_title'],
'start_date' => $row['poll_start'],
'starter_id' => $row['topic_poster'],
'votes' => array_sum( $votes ),
'poll_view_voters' => 0,
);
$poll['vote_data'] = array();
$ourVotes = array();
foreach( $this->db->select( '*', 'poll_votes', array( "topic_id=?", $row['topic_id'] ) ) AS $vote )
{
if ( !isset( $ourVotes[$vote['vote_user_id']] ) )
{
$ourVotes[$vote['vote_user_id']] = array( 'votes' => array() );
}
$ourVotes[$vote['vote_user_id']]['votes'][] = array_search( $vote['poll_option_id'], $search );
$ourVotes[$vote['vote_user_id']]['member_id'] = $vote['vote_user_id'];
}
foreach( $ourVotes AS $member_id => $vote )
{
$poll['vote_data'][$member_id] = array(
'member_id' => $vote['member_id'],
'member_choices' => array( 1 => $vote['votes'] ),
);
}
}
if ( isset( $row['topic_visibility'] ) )
{
$visibility = $row['topic_visibility'];
}
else
{
$visibility = $row['topic_approved'];
}
/* Global Topics */
if ( !$row['forum_id'] )
{
try
{
$orphaned = $this->app->getLink( '__global__', 'forums_forums' );
}
catch( \OutOfRangeException $e )
{
/* Create a forum to store it in */
$libraryClass->convertForumsForum( array(
'id' => '__global__',
'name' => 'Global Topics',
) );
}
$row['forum_id'] = '__global__';
}
$info = array(
'tid' => $row['topic_id'],
'title' => $row['topic_title'],
'forum_id' => $row['forum_id'],
'state' => ( $row['topic_status'] == 0 ) ? 'open' : 'closed',
'posts' => isset( $row['topic_posts_approved'] ) ? $row['topic_posts_approved'] : $row['topic_replies'],
'starter_id' => $row['topic_poster'],
'start_date' => $row['topic_time'],
'last_poster_id' => $row['topic_last_poster_id'],
'last_post' => $row['topic_last_post_time'],
'starter_name' => $row['topic_first_poster_name'],
'last_poster_name' => $row['topic_last_poster_name'],
'poll_state' => $poll,
'last_vote' => $row['poll_last_vote'],
'views' => $row['topic_views'],
'approved' => ( $visibility <> 1 ) ? -1 : 1,
'pinned' => ( $row['topic_type'] == 0 ) ? 0 : 1,
'topic_hiddenposts' => ( isset( $row['topic_posts_unapproved'] ) AND isset( $row['topic_posts_softdeleted'] ) ) ? $row['topic_posts_unapproved'] + $row['topic_posts_softdeleted'] : 0,
);
$libraryClass->convertForumsTopic( $info );
/* Follows */
foreach( $this->db->select( '*', 'topics_watch', array( "topic_id=?", $row['topic_id'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'topic',
'follow_rel_id' => $row['topic_id'],
'follow_rel_id_type' => 'forums_topics',
'follow_member_id' => $follow['user_id'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'follow_notify_meta' => '',
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
$libraryClass->setLastKeyValue( $row['topic_id'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'post_id' );
foreach( $this->fetch( 'posts', 'post_id' ) AS $row )
{
if ( isset( $row['post_visibility'] ) )
{
$visibility = $row['post_visibility'];
}
else
{
$visibility = $row['post_approved'];
}
$info = array(
'pid' => $row['post_id'],
'topic_id' => $row['topic_id'],
'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'],
'author_id' => $row['poster_id'],
'ip_address' => $row['poster_ip'],
'post_date' => $row['post_time'],
'queued' => ( $visibility == 1 ) ? 0 : -1,
'pdelete_time' => isset( $row['post_delete_time'] ) ? $row['post_delete_time'] : NULL,
);
$libraryClass->convertForumsPost( $info );
/* Warnings */
foreach( $this->db->select( '*', 'warnings', array( "post_id=?", $row['post_id'] ) ) AS $warning )
{
try
{
$log = $this->db->select( '*', 'log', array( "log_id=?", $warning['log_id'] ) )->first();
$data = \unserialize( $log['log_data'] );
}
catch( \UnderflowException $e )
{
$log = array( 'user_id' => 0 );
$data = array( 0 => NULL );
}
$libraryClass->convertWarnLog( array(
'wl_id' => $warn['warning_id'],
'wl_member' => $warn['user_id'],
'wl_moderator' => $log['user_id'],
'wl_date' => $warn['warning_time'],
'wl_points' => 1,
'wl_note_member' => isset( $data[0] ) ? $data[0] : NULL,
) );
}
$libraryClass->setLastKeyValue( $row['post_id'] );
}
}
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'attach_id' );
foreach( $this->fetch( 'attachments', 'attach_id' ) AS $row )
{
$map = array(
'id1' => $row['topic_id'],
'id2' => $row['post_msg_id'],
);
$info = array(
'attach_id' => $row['attach_id'],
'attach_file' => $row['real_filename'],
'attach_date' => $row['filetime'],
'attach_member_id' => $row['poster_id'],
'attach_hits' => $row['download_count'],
'attach_ext' => $row['extension'],
'attach_filesize' => $row['filesize'],
);
$libraryClass->convertAttachment( $info, $map, rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $row['physical_filename'] );
$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( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'viewtopic.php' ) !== FALSE )
{
if( isset( \IPS\Request::i()->p ) )
{
$class = '\IPS\forums\Topic\Post';
$types = array( 'posts', 'forums_posts' );
$oldId = \IPS\Request::i()->p;
}
else
{
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
$oldId = \IPS\Request::i()->tid;
}
}
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'viewforum.php' ) !== FALSE )
{
$class = '\IPS\forums\Forum';
$types = array( 'forums', 'forums_forums' );
$oldId = \IPS\Request::i()->f;
}
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\Item )
{
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;
}
}
@@ -0,0 +1,109 @@
<?php
/**
* @brief Converter PhpMyForum Forums Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 6 December 2016
* @note Only redirect scripts are supported right now
*/
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 _Phpmyforum extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "PhpMyForum";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "phpmyforum";
}
/**
* Content we can convert from this software.
*
* @return NULL
*/
public static function canConvert()
{
return NULL;
}
/**
* 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( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'board.php' ) !== FALSE )
{
try
{
$data = (string) $this->app->getLink( \IPS\Request::i()->id, array( 'forums', 'forums_forums' ) );
$item = \IPS\forums\Forum::load( $data );
if( $item->can( 'view' ) )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'topic.php' ) !== FALSE )
{
try
{
try
{
$data = (string) $this->app->getLink( \IPS\Request::i()->id, array( 'topics', 'forums_topics' ) );
}
catch( \OutOfRangeException $e )
{
$data = (string) $this->app->getLink( \IPS\Request::i()->id, array( 'topics', 'forums_topics' ), FALSE, TRUE );
}
$item = \IPS\forums\Topic::load( $data );
if( $item->canView() )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
return NULL;
}
}
@@ -0,0 +1,360 @@
<?php
/**
* @brief Converter Punbb Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 21 Jan 2015
*/
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 _Punbb extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "PunBB 1.x";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "punbb";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'forums',
'where' => NULL,
),
'convertForumsTopics' => array(
'table' => 'topics',
'where' => NULL
),
'convertForumsPosts' => array(
'table' => '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( 'punbb' ) );
}
/**
* 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( '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 ), 4, array( 'app' ) );
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics" );
}
/**
* Fix post data
*
* @param string raw post data
* @return string parsed post data
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\Punbb::fixPostData( $post );
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id' );
foreach( $this->fetch( 'forums', 'id' ) AS $row )
{
/* PunBB has separate concepts of categories versus forums - normally, we would do these in separate processes but that isn't really all that necessary */
try
{
$catId = $this->app->getLink( '1000' . $row['cat_id'], 'forums_forums' );
}
catch( \OutOfRangeException $e )
{
try
{
$category = $this->db->select( '*', 'categories', array( "id=?", $row['cat_id'] ) )->first();
$libraryClass->convertForumsForum( array(
'id' => '1000' . $category['id'],
'name' => $category['cat_name'],
'parent_id' => -1,
'position' => $category['disp_position']
) );
}
catch( \UnderflowException $e ) {}
}
/* They don't store the last poster ID. Makes me sad. */
$last_poster_id = 0;
try
{
/* Better hope they haven't changed their name */
$last_poster_id = $this->db->select( 'id', 'users', array( "username=?", $row['last_poster'] ) )->first();
}
catch( \UnderflowException $e ) {}
$info = array(
'id' => $row['id'],
'name' => $row['forum_name'],
'description' => $row['forum_desc'],
'topics' => $row['num_topics'],
'posts' => $row['num_posts'],
'last_post' => $row['last_post'],
'last_poster_id' => $last_poster_id,
'last_poster_name' => $row['last_poster'],
'parent_id' => ( $row['parent_forum_id'] == 0 ) ? '1000' . $row['cat_id'] : $row['parent_forum_id'],
'position' => $row['disp_position'],
'redirect_url' => $row['redirect_url'],
);
$libraryClass->convertForumsForum( $info );
$libraryClass->setLastKeyValue( $row['id'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id' );
foreach( $this->fetch( 'topics', 'id' ) AS $row )
{
/* sigh */
$last_poster_id = 0;
try
{
$last_poster_id = $this->db->select( 'id', 'users', array( "username=?", $row['last_poster'] ) )->first();
}
catch( \UnderflowException $e ) {}
$starter_id = 0;
try
{
$starter_id = $this->db->select( 'id', 'users', array( "username=?", $row['poster'] ) )->first();
}
catch( \UnderflowException $e ) {}
$moved_to = NULL;
if ( $row['moved_to'] )
{
try
{
$moved_to_forum = $this->db->select( 'forum_id', 'topics', array( "id=?", $row['moved_to'] ) )->first();
$moved_to = [ $row['moved_to'], $moved_to_forum ];
}
catch( \UnderflowException $e ) {}
}
$info = array(
'tid' => $row['id'],
'title' => $row['subject'],
'forum_id' => $row['forum_id'],
'state' => ( $row['closed'] ) ? 'closed' : 'open',
'posts' => $row['num_replies'],
'starter_id' => $starter_id,
'start_date' => $row['posted'],
'last_poster_id' => $last_poster_id,
'last_post' => $row['last_post'],
'starter_name' => $row['poster'],
'last_poster_name' => $row['last_poster'],
'pinned' => ( $row['sticky'] OR $row['announcement'] ) ? 1 : 0,
'moved_to' => $moved_to,
'moved_on' => ( !is_null( $moved_to ) ) ? $row['posted'] : 0,
);
$libraryClass->convertForumsTopic( $info );
foreach( $this->db->select( '*', 'subscriptions', array( "topic_id=?", $row['id'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'topic',
'follow_rel_id' => $row['id'],
'follow_rel_id_type' => 'forums_topics',
'follow_member_id' => $follow['user_id'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'follow_notify_meta' => '',
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
$libraryClass->setLastKeyValue( $row['id'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id' );
foreach( $this->fetch( 'posts', 'id' ) AS $row )
{
$info = array(
'pid' => $row['id'],
'topic_id' => $row['topic_id'],
'post' => $row['message'],
'append_edit' => ( $row['edited'] ) ? 1 : 0,
'edit_time' => $row['edited'],
'author_id' => $row['poster_id'], # I half expected them to not store this
'author_name' => $row['poster'],
'ip_address' => $row['poster_ip'],
'post_date' => $row['posted'],
'edit_name' => $row['edited_by'],
);
$libraryClass->convertForumsPost( $info );
$libraryClass->setLastKeyvalue( $row['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( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'viewtopic.php' ) !== FALSE )
{
if( isset( \IPS\Request::i()->pid ) )
{
$class = '\IPS\forums\Topic\Post';
$types = array( 'posts', 'forums_posts' );
$oldId = \IPS\Request::i()->pid;
}
else
{
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
$oldId = \IPS\Request::i()->id;
}
}
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'viewforum.php' ) !== FALSE )
{
$class = '\IPS\forums\Forum';
$types = array( 'forums', 'forums_forums' );
$oldId = \IPS\Request::i()->id;
}
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\Item )
{
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;
}
}
@@ -0,0 +1,596 @@
<?php
/**
* @brief Converter SMF Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 21 Jan 2015
*/
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 _Smf extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "Simple Machines Forum";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "smf";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsBoards' => array(
'table' => 'boards',
'where' => NULL
),
'convertForumsForums' => array(
'table' => 'forums',
'where' => NULL,
'extra_steps' => array( 'convertForumsBoards' ),
),
'convertForumsTopics' => array(
'table' => 'topics',
'where' => NULL
),
'convertForumsPosts' => array(
'table' => 'messages',
'where' => NULL
),
'convertAttachments' => array(
'table' => 'attachments',
'where' => array( "id_msg<>?", 0 )
)
);
}
/**
* 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 'forums':
return $this->db->select( 'COUNT(*)', 'categories' )->first() + $this->db->select( 'COUNT(*)', 'boards' )->first();
break;
default:
return parent::countRows( $table, $where, $recache );
break;
}
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'smf' ) );
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertAttachments'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertAttachments':
$return['convertAttachments'] = array(
'attach_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_smf_attach_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( '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( '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' ) );
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics" );
}
/**
* Fix post data
*
* @param string raw post data
* @return string parsed post data
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\Smf::fixPostData( $post );
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id_cat' );
foreach( $this->fetch( 'categories', 'id_cat', NULL, "id_cat, CONCAT( 'c', id_cat ) AS id, name, cat_order AS position, 0 AS sub_can_post, -1 AS parent_id" ) AS $row )
{
$current = $row['id_cat'];
unset( $row['id_cat'] );
$libraryClass->convertForumsForum( $row );
$libraryClass->setLastKeyValue( $current );
}
}
/**
* Convert categories
*
* @return void
*/
public function convertForumsBoards()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id_board' );
foreach( $this->fetch( 'boards', 'id_board' ) AS $row )
{
$last_post_time = 0;
$last_poster = 0;
$last_title = NULL;
$last_poster_name = NULL;
try
{
$last_post = $this->db->select( '*', 'messages', array( "id_msg=?", $row['id_last_msg'] ) )->first();
$last_post_time = $last_post['poster_time'];
$last_poster = $last_post['id_member'];
$last_poster_name = $last_post['poster_name'];
$last_title = $last_post['subject']; # Yes, I know this is technically wrong, but it's better than just not showing anything
}
catch( \UnderflowException $e ) {}
$info = array(
'id' => $row['id_board'],
'name' => $row['name'],
'description' => $row['description'],
'topics' => $row['num_topics'],
'posts' => $row['num_posts'],
'last_post' => $last_post_time,
'last_poster_id' => $last_poster,
'last_poster_name' => $last_poster_name,
'parent_id' => ( $row['id_parent'] <> 0 ) ? $row['id_parent'] : 'c' . $row['id_cat'],
'position' => $row['board_order'],
'last_title' => $last_title,
'redirect_url' => $row['redirect'],
'queued_topics' => $row['unapproved_topics'],
'queued_posts' => $row['unapproved_posts'],
);
$libraryClass->convertForumsForum( $info );
$libraryClass->setLastKeyValue( $row['id_board'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id_topic' );
foreach( $this->fetch( 'topics', 'id_topic' ) AS $row )
{
try
{
$firstPost = $this->db->select( '*', 'messages', array( "id_msg=?", $row['id_first_msg'] ) )->first();
}
catch( \UnderflowException $e )
{
$libraryClass->setLastKeyValue( $row['id_topic'] );
continue;
}
$lastPost = NULL;
try
{
$lastPost = $this->db->select( '*', 'messages', array( "id_msg=?", $row['id_last_msg'] ) )->first();
}
catch( \UnderflowException $e ) {}
$poll = NULL;
if ( $row['id_poll'] )
{
try
{
$poll_data = $this->db->select( '*', 'polls', array( "id_poll=?", $row['id_poll'] ) )->first();
$options = $this->db->select( '*', 'poll_choices', array( "id_poll=?", $poll_data['id_poll'] ) );
$choices = array();
$votes = 0;
foreach( $options AS $option )
{
$choices[ $option['id_choice'] ] = $option['label'];
$votes += $option['votes'];
}
$member_votes = array();
foreach( $this->db->select( '*', 'log_polls', array( "id_poll=?", $poll_data['id_poll'] ) ) AS $vote )
{
$member_votes[$vote['id_member']] = array(
'member_id' => $vote['id_member'],
'member_choices' => array( $vote['id_choice'] )
);
}
$poll = array(
'poll_data' => array(
'pid' => $poll_data['id_poll'],
'choices' => $choices,
'poll_question' => $poll_data['question'],
'start_date' => $firstPost['poster_time'],
'starter_id' => $poll_data['id_member'],
),
'vote_data' => $member_votes
);
}
catch( \UnderflowException $e ) {}
}
$info = array(
'tid' => $row['id_topic'],
'title' => $firstPost['subject'],
'forum_id' => $row['id_board'],
'state' => ( $row['locked'] ) ? 'closed' : 'open',
'posts' => $row['num_replies'],
'starter_id' => $row['id_member_started'],
'start_date' => $firstPost['poster_time'],
'last_poster_id' => $row['id_member_updated'],
'last_post' => ( $lastPost ) ? $lastPost['poster_time'] : 0,
'starter_name' => $firstPost['poster_name'],
'last_poster_name' => $lastPost['poster_name'],
'poll_state' => $poll,
'views' => $row['num_views'],
'approved' => $row['approved'],
'pinned' => $row['is_sticky'],
);
$libraryClass->convertForumsTopic( $info );
/* Follows */
foreach( $this->db->select( '*', 'log_notify', array( "id_topic=?", $row['id_topic'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'topic',
'follow_rel_id' => $row['id_topic'],
'follow_rel_id_type' => 'forums_topics',
'follow_member_id' => $follow['id_member'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'follow_notify_meta' => '',
'follow_notify_freq' => 'immediate',
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
$libraryClass->setLastKeyValue( $row['id_topic'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id_msg' );
foreach( $this->fetch( 'messages', 'id_msg' ) AS $row )
{
$info = array(
'pid' => $row['id_msg'],
'topic_id' => $row['id_topic'],
'post' => $row['body'],
'edit_time' => $row['modified_time'],
'author_id' => $row['id_member'],
'author_name' => $row['poster_name'],
'ip_address' => $row['poster_ip'],
'post_date' => $row['poster_time'],
'queued' => ( $row['approved'] ) ? 0 : -1,
'edit_name' => $row['modified_name'],
);
$libraryClass->convertForumsPost( $info );
$libraryClass->setLastKeyValue( $row['id_msg'] );
}
}
/**
* @brief Cached attachment paths
*/
protected static $paths = NULL;
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
if ( is_null( static::$paths ) )
{
try
{
static::$paths = @\unserialize( $this->db->select( 'value', 'settings', array( "variable=?", 'attachmentUploadDir' ) )->first() );
/* Unserialize failed. Set to an array so we don't try again */
if ( !is_array( static::$paths ) )
{
static::$paths = array();
}
}
catch( \UnderflowException $e )
{
static::$paths = array();
}
}
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'id_attach' );
foreach( $this->fetch( 'attachments', 'id_attach' ) AS $row )
{
try
{
if ( $row['id_msg'] AND $row['attachment_type'] < 3 )
{
$post = $this->db->select( 'id_topic, poster_time', 'messages', array( "id_msg=?", $row['id_msg'] ) )->first();
}
else
{
/* Is an avatar or thumbnail */
throw new \UnderflowException;
}
}
catch( \UnderflowException $e )
{
$libraryClass->setLastKeyValue( $row['id_attach'] );
continue;
}
/* Map */
$map = array(
'id1' => $post['id_topic'],
'id2' => $row['id_msg'],
);
/* We need to figure out where it is */
if ( $row['file_hash'] )
{
$location = $row['id_attach'] . '_' . $row['file_hash'];
}
else
{
/* Clean filename per legacy SMF requirements */
$cleanName = strtr( $row['filename'], 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
$cleanName = strtr( $cleanName, array( 'Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u' ) );
$cleanName = preg_replace( array( '/s/', '/[^w_.-]/' ), array( '_', '' ), $cleanName );
$location = $row['id_attach'] . '_' . str_replace( '.', '_', $cleanName ) . md5( $cleanName );
}
$location = str_replace( ' ', '_', $location );
/* Fix File Name */
// http://community.invisionpower.com/tracker/issue-21020-smf-attachments-are-crazy/
$row['filename'] = str_replace(' ', '_', $row['filename']);
$row['filename'] = str_replace('!', '', $row['filename']);
$row['filename'] = str_replace('(', '', $row['filename']);
$row['filename'] = str_replace(')', '', $row['filename']);
$row['filename'] = str_replace(',', '', $row['filename']);
$row['filename'] = str_replace('[', '', $row['filename']);
$row['filename'] = str_replace(']', '', $row['filename']);
$row['filename'] = str_replace('&', '', $row['filename']);
$row['filename'] = str_replace('\'', '', $row['filename']);
$row['filename'] = str_replace( chr(195) . chr(182) , 'A', $row['filename']);
$row['filename'] = str_replace( chr(195) . chr(164) , 'A', $row['filename']);
/* General Information */
$info = array(
'attach_id' => $row['id_attach'],
'attach_file' => $row['filename'],
'attach_member_id' => $row['id_member'],
'attach_hits' => $row['downloads'],
'attach_date' => $post['poster_time'],
'attach_ext' => $row['fileext'],
'attach_filesize' => $row['size']
);
if ( $row['id_folder'] AND $row['id_folder'] != 1 )
{
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $location;
}
else
{
if ( isset( static::$paths[ $row['id_folder'] ] ) )
{
$path = rtrim( static::$paths[ $row['id_folder'] ], '/' ) . '/' . $location;
}
else
{
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $location;
}
}
$libraryClass->convertAttachment( $info, $map, $path );
$libraryClass->setLastKeyValue( $row['id_attach'] );
}
}
/**
* Check if we can redirect the legacy URLs from this software to the new locations
*
* @return NULL|\IPS\Http\Url
*/
public function checkRedirects()
{
if( isset( \IPS\Request::i()->topic ) )
{
if( mb_strpos( \IPS\Request::i()->topic, '.msg' ) !== FALSE )
{
$class = '\IPS\forums\Topic\Post';
$types = array( 'posts', 'forums_posts' );
$oldId = mb_substr( \IPS\Request::i()->topic, mb_strpos( \IPS\Request::i()->topic, '.msg' ) + 4 );
}
else
{
$pieces = explode( '.', \IPS\Request::i()->topic );
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
$oldId = $pieces[0];
}
}
elseif( isset( \IPS\Request::i()->board ) )
{
$class = '\IPS\forums\Forum';
$types = array( 'forums', 'forums_forums' );
$oldId = \IPS\Request::i()->board;
}
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\Item )
{
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;
}
}
@@ -0,0 +1,536 @@
<?php
/**
* @brief Converter UBBthreads Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2015 Invision Power Services, Inc.
* @package IPS Social Suite
* @subpackage Converter
* @since 21 Jan 2015
* @version
*/
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 _UBBthreads extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "UBBthreads";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "UBBthreads";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'CATEGORIES',
'where' => NULL,
'extra_steps' => array( 'convertForumsForumsFollowers' )
),
'convertForumsForumsFollowers' => array(
'table' => 'WATCH_LISTS',
'where' => array( 'WATCH_TYPE=?', 'f' )
),
'convertForumsTopics' => array(
'table' => 'TOPICS',
'where' => NULL,
'extra_steps' => array( 'convertForumsTopicsRatings', 'convertForumsTopicsFollowers' )
),
'convertForumsTopicsRatings' => array(
'table' => 'RATINGS',
'where' => array( 'RATING_TYPE=?', 't' )
),
'convertForumsTopicsFollowers' => array(
'table' => 'WATCH_LISTS',
'where' => array( 'WATCH_TYPE=?', 't' )
),
'convertForumsPosts' => array(
'table' => 'POSTS',
'where' => NULL
),
'convertAttachments' => array(
'table' => 'FILES',
'where' => array( 'POST_ID>?', 0 )
)
);
}
/**
* 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 'CATEGORIES':
return parent::countRows( 'CATEGORIES' ) + parent::countRows( 'FORUMS' );
}
return parent::countRows( $table, $where, $recache );
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'UBBthreads' ) );
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertAttachments'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertAttachments':
$return['convertAttachments'] = array(
'attach_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_ubb_attach_path'),
),
);
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( '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( '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' ) );
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics" );
}
/**
* Fix post data
*
* @param string raw post data
* @return string parsed post data
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\UBBthreads::fixPostData( $post );
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
/**
* Categories in UBB are abstracted. So, before we actually convert any real "forums", we will want to convert
* the categories they are contained in.
*/
foreach ( $this->db->select( '*', 'CATEGORIES' ) as $row )
{
$libraryClass->convertForumsForum( array(
'id' => 10000 + $row['CATEGORY_ID'],
'name' => $row['CATEGORY_TITLE'],
'description' => $row['CATEGORY_DESCRIPTION'],
'position' => $row['CATEGORY_SORT_ORDER'],
'sub_can_post' => 0,
'parent_id' => -1
) );
}
/* Here is where we actually convert the real forums */
foreach( $this->db->select( '*', 'FORUMS' ) AS $row )
{
$libraryClass->convertForumsForum( array(
'id' => $row['FORUM_ID'],
'name' => $row['FORUM_TITLE'],
'description' => $row['FORUM_DESCRIPTION'],
'topics' => $row['FORUM_TOPICS'],
'posts' => $row['FORUM_POSTS'],
'last_post' => \IPS\DateTime::create()->setTimestamp( $row['FORUM_LAST_POST_TIME'] ),
'last_poster_id' => $row['FORUM_LAST_POSTER_ID'],
'last_poster_name' => $row['FORUM_LAST_POSTER_NAME'],
'parent_id' => $row['FORUM_PARENT_ID'] ?: ( 10000 + $row['CATEGORY_ID'] ),
'position' => $row['FORUM_SORT_ORDER'],
'last_title' => $row['FORUM_LAST_POST_SUBJECT'],
'allow_poll' => $row['FORUM_ALLOW_POLLS']
) );
}
throw new \IPS\convert\Software\Exception;
}
/**
* Convert forum followers
*
* @return void
*/
public function convertForumsForumsFollowers()
{
$libraryClass = $this->getLibrary();
foreach ( $this->fetch( 'WATCH_LISTS', 'WATCH_ID', array( 'WATCH_TYPE=?', 'f' ), 'USER_ID ASC, WATCH_ID ASC' ) as $row )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'forum',
'follow_rel_id' => $row['WATCH_ID'],
'follow_rel_id_type' => 'forums_forums',
'follow_member_id' => $row['USER_ID'],
'follow_notify_freq' => $row['WATCH_NOTIFY_IMMEDIATE'] ? 'immediate' : 'none',
) );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'TOPIC_ID' );
foreach ( $this->fetch( 'TOPICS', 'TOPIC_ID' ) as $row )
{
/* Poll */
$poll = NULL;
if ( $row['TOPIC_HAS_POLL'] > 0 )
{
try
{
$pollData = $this->db->select( '*', 'POLL_DATA', array( "POST_ID=?", $row['POST_ID'] ) )->first();
$choices = array();
$index = 1;
foreach( $this->db->select( '*', 'POLL_OPTIONS', array( 'POLL_ID=?', $pollData['POLL_ID'] ), 'OPTION_ID ASC' ) AS $choice )
{
$choices[ $index ] = strip_tags( $choice['CHOICE_BODY'] ); // Unlike forum titles, I don't believe we allow HTML in poll choices
$index++;
}
/* Reset Index */
$index = 1;
$votes = array();
$rawVotes = iterator_to_array( $this->db->select( '*', 'POLL_VOTES', array( 'POLL_ID=?', $pollData['POLL_ID'] ) ) );
foreach( $rawVotes AS $vote )
{
$votes[ $index ] = $vote['OPTION_ID'];
$index++;
}
$poll = array();
$poll['poll_data'] = array(
'pid' => $pollData['POLL_ID'],
'choices' => array( 1 => array(
'question' => strip_tags( $pollData['POLL_BODY'] ),
'multi' => ( $pollData['POLL_TYPE'] != 'one' ),
'choice' => $choices,
'votes' => $votes
) ),
'poll_question' => strip_tags( $pollData['POLL_BODY'] ),
'start_date' => \IPS\DateTime::create()->setTimestamp( $row['POLL_START_TIME'] ),
'starter_id' => $row['USER_ID'],
);
$poll['vote_data'] = array();
$ourVotes = array();
foreach( $rawVotes AS $vote )
{
/* "Votes need a member account", apparently, so we will probably lose guest votes </sigh> */
if ( !isset( $ourVotes[ $vote['VOTES_USER_ID_IP'] ] ) )
{
$ourVotes[ $vote['VOTES_USER_ID_IP'] ] = array( 'votes' => array() );
}
$ourVotes[ $vote['uid'] ]['votes'][] = $vote['OPTION_ID'];
$ourVotes[ $vote['uid'] ]['member_id'] = $vote['VOTES_USER_ID_IP'];
}
/* Now we need to re-wrap it all for storage */
foreach( $ourVotes AS $member_id => $vote )
{
$poll['vote_data'][ $member_id ] = array(
'vote_date' => $vote['vote_date'],
'member_id' => $vote['member_id'],
'member_choices' => array( 1 => $vote['votes'] ),
);
}
}
catch( \UnderflowException $e ) {} # if the poll is missing, don't bother
}
$libraryClass->convertForumsTopic( array(
'tid' => $row['TOPIC_ID'],
'title' => mb_substr( $row['TOPIC_SUBJECT'], 0, 250 ),
'forum_id' => $row['FORUM_ID'],
'state' => ( $row['TOPIC_STATUS'] == 'C' ) ? 'closed' : 'open',
'posts' => $row['TOPIC_TOTAL_REPLIES'],
'starter_id' => $row['USER_ID'],
'start_date' => \IPS\DateTime::create()->setTimestamp( $row['TOPIC_CREATED_TIME'] ),
'last_poster_id' => $row['TOPIC_LAST_POSTER_ID'],
'last_post' => \IPS\DateTime::create()->setTimestamp( $row['TOPIC_LAST_REPLY_TIME'] ),
'last_poster_name' => $row['TOPIC_LAST_POSTER_NAME'],
'views' => $row['TOPIC_VIEWS'],
'approved' => $row['TOPIC_IS_APPROVED'],
'pinned' => $row['TOPIC_IS_STICKY'],
'poll_state' => $poll
) );
$libraryClass->setLastKeyValue( $row['TOPIC_ID'] );
}
}
/**
* Convert topic ratings
*
* @return void
*/
public function convertForumsTopicsRatings()
{
$libraryClass = $this->getLibrary();
foreach ( $this->db->select( '*', 'RATINGS', array( 'RATING_TYPE=?', 't' ) ) as $row )
{
$libraryClass->convertRating( array(
'class' => 'IPS\\forums\\Topic',
'item_link' => 'forums_topics',
'item_id' => $row['RATING_TARGET'],
'rating' => $row['RATING_VALUE'],
'member' => $row['RATING_RATER']
) );
}
}
/**
* Convert topic followers
*
* @return void
*/
public function convertForumsTopicsFollowers()
{
$libraryClass = $this->getLibrary();
foreach ( $this->fetch( 'WATCH_LISTS', 'WATCH_ID', array( 'WATCH_TYPE=?', 't' ), 'USER_ID ASC, WATCH_ID ASC' ) as $row )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'topic',
'follow_rel_id' => $row['WATCH_ID'],
'follow_rel_id_type' => 'forums_topics',
'follow_member_id' => $row['USER_ID'],
'follow_notify_freq' => $row['WATCH_NOTIFY_IMMEDIATE'] ? 'immediate' : 'none',
) );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'POST_ID' );
foreach ( $this->fetch( 'POSTS', 'POST_ID' ) as $row )
{
$libraryClass->convertForumsPost( array(
'pid' => $row['POST_ID'],
'topic_id' => $row['TOPIC_ID'],
'post' => $row['POST_DEFAULT_BODY'],
'append_edit' => ( (int) $row['POST_LAST_EDITED_TIME'] > 0 ),
'edit_time' => $row['POST_LAST_EDITED_TIME'],
'edit_name' => $row['POST_LAST_EDITED_BY'],
'author_id' => $row['USER_ID'],
'author_name' => $row['POST_POSTER_NAME'],
'ip_address' => $row['POST_POSTER_IP'],
'post_date' => \IPS\DateTime::create()->setTimestamp( $row['POST_POSTED_TIME'] ),
'queued' => ( ! $row['POST_IS_APPROVED'] ),
'new_topic' => $row['POST_IS_TOPIC'],
) );
$libraryClass->setLastKeyValue( $row['POST_ID'] );
}
}
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'FILE_ID' );
/* Only load files with a post id */
foreach( $this->fetch( 'FILES', 'FILE_ID', array( 'POST_ID>?', 0 ) ) AS $row )
{
$map = array();
/* Try to load the topic ID */
try
{
$topicId = $this->db->select( 'TOPIC_ID', 'POSTS', array( "POST_ID=?", $row['POST_ID'] ) )->first();
$map['id1'] = $topicId;
$map['id2'] = $row['POST_ID'];
}
catch( \UnderflowException $e ) {}
$info = array(
'attach_id' => $row['FILE_ID'],
'attach_file' => $row['FILE_NAME'],
'attach_date' => \IPS\DateTime::create()->setTimestamp( $row['FILE_ADD_TIME'] ),
'attach_member_id' => $row['USER_ID'],
'attach_hits' => $row['FILE_DOWNLOADS'],
'attach_ext' => pathinfo( $row['FILE_NAME'], \PATHINFO_EXTENSION ),
'attach_filesize' => $row['FILE_SIZE'], // Note: Apparently not always readily available?
);
$libraryClass->convertAttachment( $info, $map, rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $row['FILE_NAME'] );
$libraryClass->setLastKeyValue( $row['FILE_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();
/* Make sure it's a UBBThreads URL */
if( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'ubbthreads.php' ) === FALSE )
{
return NULL;
}
if( preg_match( '#/ubbthreads.php/topics/([0-9]+)($|/)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
try
{
try
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'topics', 'forums_topics' ) );
}
catch( \OutOfRangeException $e )
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'topics', 'forums_topics' ), FALSE, TRUE );
}
$item = \IPS\forums\Topic::load( $data );
if( $item->canView() )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
elseif( preg_match( '#/ubbthreads.php/forums/([0-9]+)($|/)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
try
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'forums', 'forums_forums' ) );
$item = \IPS\forums\Forum::load( $data );
if( $item->can( 'view' ) )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
return NULL;
}
}
@@ -0,0 +1,522 @@
<?php
/**
* @brief Converter Vanilla Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2015 Invision Power Services, Inc.
* @package IPS Social Suite
* @subpackage Converter
* @since 21 Jan 2015
* @version
*/
namespace IPS\convert\Software\Forums;
use \IPS\convert\Software\Core\Vanilla as VanillaCore;
/* 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 _Vanilla extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "Vanilla 2";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "vanilla";
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'vanilla' ) );
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'Category',
'where' => NULL
),
'convertForumsTopics' => array(
'table' => 'Discussion',
'where' => NULL
),
'convertForumsPosts' => array(
'table' => 'Comment',
'where' => NULL,
'extra_steps' => array( 'convertForumsPosts2' )
),
'convertForumsPosts2' => array(
'table' => 'Comment',
'where' => NULL
),
'convertAttachments' => array(
'table' => 'Media',
'where' => array( 'ForeignTable=? OR ForeignTable=?', 'discussion', 'comment' )
)
);
}
/**
* 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 'Comment':
$count = 0;
$count += $this->db->select( 'COUNT(*)', 'Discussion' )->first();
$count += $this->db->select( 'COUNT(*)', 'Comment' )->first();
return $count;
break;
default:
return parent::countRows( $table, $where, $recache );
break;
}
}
/**
* Can we convert passwords from this software.
*
* @return boolean
*/
public static function loginEnabled()
{
return TRUE;
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertForums',
'convertAttachments'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertForums':
$return['convertForums'] = array();
/* Find out where the photos live */
\IPS\Member::loggedIn()->language()->words['attach_location_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'attach_location' );
$return['convertForums']['attach_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_vanilla_photopath'),
);
break;
case 'convertAttachments':
$return['convertAttachments'] = array(
'attach_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_vanilla_photopath'),
'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( '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( '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' ) );
/* 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 raw post data
* @return string parsed post data
*/
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.
*/
$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 );
return $quoted ?: $post;
}
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'MediaID' );
foreach( $this->fetch( 'Media', 'MediaID', array( 'ForeignTable=? OR ForeignTable=?', 'discussion', 'comment' ) ) AS $row )
{
if( $row['ForeignTable'] == 'discussion' )
{
$map = array(
'id1' => 'fp-' . $row['ForeignID'],
'id2' => $row['ForeignID'],
);
}
else
{
try
{
$discussionId = $this->db->select( 'DiscussionID', 'Comment', array( 'CommentID=?', $row['ForeignID'] ) )->first();
}
catch( \UnderflowException $ex )
{
$libraryClass->setLastKeyValue( $row['MediaID'] );
}
$map = array(
'id1' => $discussionId,
'id2' => $row['ForeignID'],
);
}
/* File extension */
$ext = explode( '.', $row['Path'] );
$ext = array_pop( $ext );
$info = array(
'attach_id' => $row['MediaID'],
'attach_file' => $row['Name'],
'attach_date' => VanillaCore::mysqlToDateTime( $row['DateInserted'] ),
'attach_member_id' => $row['InsertUserID'],
'attach_hits' => 0,
'attach_ext' => $ext,
'attach_filesize' => $row['Size'],
);
$libraryClass->convertAttachment( $info, $map, rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . trim( $row['Path'], '/' ) );
$libraryClass->setLastKeyValue( $row['MediaID'] );
}
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'c.CategoryID' );
$uploadsPath = $this->app->_session['more_info']['convertAttachments']['attach_location'];
$forums = $this->fetch( array( 'Category', 'c' ), 'CategoryID', array( 'c.CategoryID<>?', -1 ),
'c.*, lcu.UserID as LastCommentUserID, lcu.Name as LastCommentUserName, ld.Name as LastDiscussionName'
);
$forums->join( array( 'User', 'lcu' ), 'c.LastCommentID=lcu.UserID' );
$forums->join( array( 'Discussion', 'ld' ), 'c.LastDiscussionID=ld.DiscussionID' );
foreach( $forums AS $row )
{
$icon = $row['Icon'] ? VanillaCore::parseMediaLocation( $row['Icon'], $uploadsPath ) : NULL;
$info = [
'id' => $row['CategoryID'],
'name' => $row['Name'],
'description' => $row['Description'],
'topics' => $row['CountDiscussions'],
'posts' => $row['CountComments'],
'last_post' => VanillaCore::mysqlToDateTime( $row['LastDateInserted'] ),
'last_poster_id' => $row['LastCommentID'],
'last_poster_name' => $row['LastCommentUserName'],
'parent_id' => ( (int) $row['ParentCategoryID'] > 0 ) ? $row['ParentCategoryID'] : NULL,
'position' => $row['Sort'],
'last_title' => $row['LastDiscussionName'],
'icon' => $icon,
'sub_can_post' => $row['AllowDiscussions'] ?: 0
];
$libraryClass->convertForumsForum( $info, NULL, $icon );
$libraryClass->setLastKeyValue( $row['CategoryID'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'd.DiscussionID' );
$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 )
{
/* 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();
$row['DateLastComment'] = $data['DateInserted'];
$row['LastCommentUserId'] = $data['InsertUserId'];
$row['LastCommentUserName'] = $data['Name'];
}
$info = array(
'tid' => $row['DiscussionID'],
'title' => $row['Name'],
'forum_id' => $row['CategoryID'],
'state' => ( $row['Closed'] == 0 ) ? 'open' : 'closed',
'posts' => $row['CountComments'],
'starter_id' => $row['InsertUserID'],
'start_date' => VanillaCore::mysqlToDateTime( $row['DateInserted'] ),
'last_poster_id' => $row['LastCommentUserId'],
'last_post' => VanillaCore::mysqlToDateTime( $row['DateLastComment'] ),
'starter_name' => $row['UserName'],
'last_poster_name' => $row['LastCommentUserName'],
'views' => $row['CountViews'],
);
$libraryClass->convertForumsTopic( $info );
/* Tags */
if( !empty( $row['Tags'] ) )
{
$tags = explode( ',', $row['Tags'] );
if ( count( $tags ) )
{
foreach( $tags AS $tag )
{
$toConvert = explode( ' ', $tag );
foreach( $toConvert as $spacedTag )
{
$libraryClass->convertTag( array(
'tag_meta_app' => 'forums',
'tag_meta_area' => 'forums',
'tag_meta_parent_id' => $row['CategoryID'],
'tag_meta_id' => $row['DiscussionID'],
'tag_text' => $spacedTag,
'tag_member_id' => $row['InsertUserID'],
'tag_prefix' => 0,
) );
}
}
}
}
$libraryClass->setLastKeyValue( $row['DiscussionID'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'DiscussionID' );
foreach( $this->fetch( 'Discussion', 'DiscussionID' ) AS $row )
{
$editName = NULL;
if( $row['UpdateUserID'] )
{
try
{
$editName = $this->db->select( 'Name', 'User', array( 'UserID=?', $row['UpdateUserID'] ) )->first();
}
catch( \UnderflowException $e ) {}
}
// First post
$info = array(
'pid' => 'fp-' . $row['DiscussionID'],
'topic_id' => $row['DiscussionID'],
'post' => $row['Body'],
'new_topic' => 1,
'edit_time' => ( $editName === NULL ) ? NULL : VanillaCore::mysqlToDateTime( $row['DateUpdated'] ),
'edit_name' => $editName,
'author_id' => $row['InsertUserID'],
'ip_address' => $row['InsertIPAddress'],
'post_date' => VanillaCore::mysqlToDateTime( $row['DateInserted'] ),
);
$libraryClass->convertForumsPost( $info );
$libraryClass->setLastKeyValue( $row['DiscussionID'] );
}
}
/**
* Convert other posts
*
* @return void
*/
public function convertForumsPosts2()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'CommentID' );
foreach( $this->fetch( 'Comment', 'CommentID' ) AS $row )
{
$editName = NULL;
if( $row['UpdateUserID'] )
{
try
{
$editName = $this->db->select( 'Name', 'User', array( 'UserID=?', $row['UpdateUserID'] ) )->first();
}
catch( \UnderflowException $e ) {}
}
$info = [
'pid' => $row['CommentID'],
'topic_id' => $row['DiscussionID'],
'post' => $row['Body'],
'edit_time' => ( $editName === NULL ) ? NULL : VanillaCore::mysqlToDateTime( $row['DateUpdated'] ),
'edit_name' => $editName,
'author_id' => $row['InsertUserID'],
'ip_address' => $row['InsertIPAddress'],
'post_date' => VanillaCore::mysqlToDateTime( $row['DateInserted'] ),
];
$libraryClass->convertForumsPost( $info );
$libraryClass->setLastKeyValue( $row['CommentID'] );
}
}
/**
* Check if we can redirect the legacy URLs from this software to the new locations
*
* @return NULL|\IPS\Http\Url
* @note Forums and profiles don't use an ID in the URL. While we may be able to somehow cross reference this with our SEO slug, it wouldn't be reliable.
*/
public function checkRedirects()
{
$url = \IPS\Request::i()->url();
if( preg_match( '#/discussion/([0-9]+)/#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
try
{
try
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'topics', 'forums_topics' ) );
}
catch( \OutOfRangeException $e )
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'topics', 'forums_topics' ), FALSE, TRUE );
}
$item = \IPS\forums\Topic::load( $data );
if( $item->canView() )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
return NULL;
}
}
@@ -0,0 +1,999 @@
<?php
/**
* @brief Converter vBulletin 4.x Forums Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 21 Jan 2015
*/
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 _Vbulletin extends \IPS\convert\Software
{
/**
* @brief vBulletin 4 Stores all attachments under one table - this will store the content type for the forums app.
*/
protected static $postContentType = NULL;
/**
* @brief The schematic for vB3 and vB4 is similar enough that we can make specific concessions in a single converter for either version.
*/
protected 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 vB3 or vB4? */
if ( static::$isLegacy === NULL )
{
$version = $this->db->select( 'value', 'setting', array( "varname=?", 'templateversion' ) )->first();
if ( mb_substr( $version, 0, 1 ) == '3' )
{
static::$isLegacy = TRUE;
}
else
{
static::$isLegacy = FALSE;
}
}
/* If this is vB4, what is the content type ID for posts? */
if ( static::$postContentType === NULL AND ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) ) )
{
static::$postContentType = $this->db->select( 'contenttypeid', 'contenttype', array( "class=?", 'Post' ) )->first();
}
}
catch( \Exception $e ) {}
}
return $return;
}
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "vBulletin Forums (3.x/4.x)";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "vbulletin";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'forum',
'where' => NULL,
),
'convertForumsTopics' => array(
'table' => 'thread',
'where' => NULL
),
'convertForumsPosts' => array(
'table' => 'post',
'where' => NULL
),
'convertAttachments' => array(
'table' => 'attachment',
'where' => ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) ) ? array( "contenttypeid=?", static::$postContentType ) : NULL
)
);
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'vbulletin' ) );
}
/**
* 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( '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 ), 4, array( 'app' ) );
/* 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
* @return string Fixed Posts
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\Vbulletin::fixPostData( $post );
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array( 'convertAttachments' );
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertAttachments':
$return['convertAttachments'] = array(
'file_location' => array(
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => 'database',
'field_required' => TRUE,
'field_extra' => array(
'options' => array(
'database' => \IPS\Member::loggedIn()->language()->addToStack( 'database' ),
'file_system' => \IPS\Member::loggedIn()->language()->addToStack( 'file_system' ),
),
'userSuppliedInput' => 'file_system',
),
'field_hint' => NULL,
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
)
);
break;
}
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'forumid' );
foreach( $this->fetch( 'forum', 'forumid' ) AS $forum )
{
$self = $this;
$checkpermission = function( $name, $perm ) use ( $forum, $self )
{
$key = $name;
if ( $name == 'forumoptions' )
{
$key = 'options';
}
if ( $forum[$key] & $self::$bitOptions[$name][$perm] )
{
return TRUE;
}
return FALSE;
};
$info = array(
'id' => $forum['forumid'],
'name' => $forum['title'],
'description' => $forum['description'],
'topics' => $forum['threadcount'],
'posts' => $forum['replycount'],
'last_post' => $forum['lastpost'],
'last_poster_id' => ( static::$isLegacy === FALSE or is_null( static::$isLegacy ) ) ? $forum['lastposterid'] : 0,
'last_poster_name' => $forum['lastposter'],
'parent_id' => $forum['parentid'],
'position' => $forum['displayorder'],
'password' => $forum['password'] ?: NULL,
'last_title' => $forum['lastthread'],
'preview_posts' => $checkpermission( 'forumoptions', 'moderatenewpost' ),
'inc_postcount' => $checkpermission( 'forumoptions', 'countposts' ),
'redirect_url' => $forum['link'],
'sub_can_post' => $checkpermission( 'forumoptions', 'cancontainthreads' ),
'forum_allow_rating' => $checkpermission( 'forumoptions', 'allowratings' ),
);
$libraryClass->convertForumsForum( $info );
/* Follows for this forum */
foreach( $this->db->select( '*', 'subscribeforum', array( "forumid=?", $forum['forumid'] ) ) AS $follow )
{
$frequency = 'none';
switch( $follow['emailupdate'] )
{
case 1:
$frequency = 'immediate';
break;
case 2:
$frequency = 'daily';
break;
case 3:
$frequency = 'weekly';
break;
}
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'forum',
'follow_rel_id' => $forum['forumid'],
'follow_rel_id_type' => 'forums_forums',
'follow_member_id' => $follow['userid'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'follow_notify_meta' => '',
'follow_notify_freq' => $frequency,
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
$libraryClass->setLastKeyValue( $forum['forumid'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'threadid' );
foreach( $this->fetch( 'thread', 'threadid' ) AS $topic )
{
/* Pesky Polls */
$poll = NULL;
$lastVote = 0;
if ( $topic['pollid'] > 0 )
{
try
{
$pollData = $this->db->select( '*', 'poll', array( "pollid=?", $topic['pollid'] ) )->first();
$lastVote = $pollData['lastvote'];
$choices = array();
$index = 1;
foreach( explode( '|||', $pollData['options'] ) AS $choice )
{
$choices[$index] = trim( $choice );
$index++;
}
/* Reset Index */
$index = 1;
$votes = array();
$numvotes = 0;
foreach( explode( '|||', $pollData['votes'] ) AS $vote )
{
$votes[$index] = $vote;
$index++;
$numvotes += $vote;
}
$poll = array();
$poll['poll_data'] = array(
'pid' => $pollData['pollid'],
'choices' => array( 1 => array(
'question' => $pollData['question'],
'multi' => $pollData['multiple'],
'choice' => $choices,
'votes' => $votes
) ),
'poll_question' => $pollData['question'],
'start_date' => $pollData['dateline'],
'starter_id' => $topic['postuserid'],
'votes' => $numvotes,
'poll_view_voters' => $pollData['public']
);
$poll['vote_data'] = array();
$ourVotes = array();
foreach( $this->db->select( '*', 'pollvote', array( "pollid=?", $pollData['pollid'] ) ) AS $vote )
{
if ( !isset( $ourVotes[$vote['userid']] ) )
{
/* Create our structure - vB stores each individual vote as a different row whereas we combine them per user */
$ourVotes[$vote['userid']] = array( 'votes' => array() );
}
$ourVotes[$vote['userid']]['votes'][] = $vote['voteoption'];
/* These don't matter - just use the latest one */
$ourVotes[$vote['userid']]['vid'] = $vote['pollvoteid'];
$ourVotes[$vote['userid']]['vote_date'] = $vote['votedate'];
$ourVotes[$vote['userid']]['member_id'] = $vote['userid'];
}
/* Now we need to re-wrap it all for storage */
foreach( $ourVotes AS $member_id => $vote )
{
$poll['vote_data'][$member_id] = array(
'vid' => $vote['vid'],
'vote_date' => $vote['vote_date'],
'member_id' => $vote['member_id'],
'member_choices' => array( 1 => $vote['votes'] ),
);
}
}
catch( \UnderflowException $e ) {} # if the poll is missing, don't bother
}
$info = array(
'tid' => $topic['threadid'],
'title' => $topic['title'],
'forum_id' => $topic['forumid'],
'state' => $topic['open'] ? 'open' : 'closed',
'posts' => $topic['replycount'],
'starter_id' => $topic['postuserid'],
'start_date' => $topic['dateline'],
'last_poster_id' => ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) ) ? $topic['lastposterid'] : NULL,
'last_post' => $topic['lastpost'],
'starter_name' => $topic['postusername'],
'last_poster_name' => $topic['lastposter'],
'poll_state' => $poll,
'last_vote' => $lastVote,
'views' => $topic['views'],
'approved' => $topic['visible'],
'pinned' => $topic['sticky'],
'topic_open_time' => $topic['dateline'],
'topic_hiddenposts' => $topic['hiddencount'] + $topic['deletedcount']
);
unset( $poll );
$topic_id = $libraryClass->convertForumsTopic( $info );
/* Follows */
foreach( $this->db->select( '*', 'subscribethread', array( "threadid=?", $topic['threadid'] ) ) AS $follow )
{
$frequency = 'none';
switch( $follow['emailupdate'] )
{
case 1:
$frequency = 'immediate';
break;
case 2:
$frequency = 'daily';
break;
case 3:
$frequency = 'weekly';
break;
}
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'topic',
'follow_rel_id' => $topic['threadid'],
'follow_rel_id_type' => 'forums_topics',
'follow_member_id' => $follow['userid'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'follow_notify_meta' => '',
'follow_notify_freq' => $frequency,
'follow_notify_sent' => 0,
'follow_visible' => 1,
'follow_index_id' => NULL
) );
}
/* Ratings */
foreach( $this->db->select( '*', 'threadrate', array( "threadid=?", $topic['threadid'] ) ) AS $rating )
{
$libraryClass->convertRating( array(
'id' => $rating['threadrateid'],
'class' => 'IPS\\forums\\Topic',
'item_link' => 'forums_topics',
'item_id' => $rating['threadid'],
'ip' => $rating['ipaddress'],
'rating' => $rating['vote'],
'member' => $rating['userid']
) );
}
/* Tag Prefix */
try
{
$prefix = $this->db->select( '*', 'prefix', array( "prefixid=?", $topic['prefixid'] ) )->first();
$lang = $this->db->select( '*', 'phrase', array( "varname=?", "prefix_{$prefix['prefixid']}_title_plain" ) )->first();
$libraryClass->convertTag( array(
'tag_meta_app' => 'forums',
'tag_meta_area' => 'forums',
'tag_meta_parent_id' => $topic['forumid'],
'tag_meta_id' => $topic['threadid'],
'tag_text' => $lang['text'],
'tag_member_id' => $topic['postuserid'],
'tag_prefix' => 1, # key to this whole operation right here
) );
}
catch( \UnderflowException $e ) {}
/* Tags */
if( $topic['taglist'] !== NULL AND !empty( $topic['taglist'] ) )
{
$tags = explode( ',', $topic['taglist'] );
if ( count( $tags ) )
{
foreach( $tags AS $tag )
{
$libraryClass->convertTag( array(
'tag_meta_app' => 'forums',
'tag_meta_area' => 'forums',
'tag_meta_parent_id' => $topic['forumid'],
'tag_meta_id' => $topic['threadid'],
'tag_text' => $tag,
'tag_member_id' => $topic['postuserid'],
'tag_prefix' => 0,
) );
}
}
}
$libraryClass->setLastKeyValue( $topic['threadid'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'postid' );
foreach( $this->fetch( 'post', 'postid' ) AS $post )
{
$info = array(
'pid' => $post['postid'],
'topic_id' => $post['threadid'],
'post' => static::fixPostData( $post['pagetext'] ),
'author_id' => $post['userid'],
'author_name' => $post['username'],
'ip_address' => $post['ipaddress'],
'post_date' => $post['dateline'],
'queued' => ( $post['visible'] >= 2 ) ? -1 : ( ( $post['visible'] == 0 ) ? 1 : 0 ),
'post_htmlstate' => ( static::$isLegacy === FALSE AND in_array( $post['htmlstate'], array( 'on', 'on_nl2br' ) ) ) ? 1 : 0,
);
$post_id = $libraryClass->convertForumsPost( $info );
/* Reputation */
foreach( $this->db->select( '*', 'reputation', array( "postid=?", $post['postid'] ) ) AS $rep )
{
$libraryClass->convertReputation( array(
'id' => $rep['reputationid'],
'app' => 'forums',
'type' => 'pid',
'type_id' => $post['postid'],
'member_id' => $rep['whoadded'],
'member_received' => $rep['userid'],
'rep_date' => $rep['dateline'],
'rep_rating' => $rep['reputation']
) );
}
/* Edit History */
$latestedit = 0;
$reason = NULL;
$name = NULL;
foreach( $this->db->select( '*', 'postedithistory', array( "postid=?", $post['postid'] ) ) AS $edit )
{
$libraryClass->convertEditHistory( array(
'id' => $edit['postedithistoryid'],
'class' => 'IPS\\forums\\Topic\\Post',
'comment_id' => $post['postid'],
'member' => $edit['userid'],
'time' => $edit['dateline'],
'old' => $edit['pagetext']
) );
if ( $edit['dateline'] > $latestedit )
{
$latestedit = $edit['dateline'];
$reason = $edit['reason'];
$name = $edit['username'];
}
}
/* Warnings */
foreach( $this->db->select( '*', 'infraction', array( "postid=?", $post['postid'] ) ) AS $warn )
{
$libraryClass->convertWarnLog( array(
'wl_id' => $warn['infractionid'],
'wl_member' => $warn['userid'],
'wl_moderator' => $warn['whoadded'],
'wl_date' => $warn['dateline'],
'wl_points' => $warn['points'],
'wl_note_member' => $warn['note'],
'wl_note_mods' => $warn['customreason'],
) );
}
/* 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 */
if ( $latestedit )
{
\IPS\Db::i()->update( 'forums_posts', array( 'append_edit' => 1, 'edit_time' => $latestedit, 'edit_name' => $name, 'post_edit_reason' => $reason ), array( "pid=?", $post_id ) );
}
$libraryClass->setLastKeyValue( $post['postid'] );
}
}
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'attachmentid' );
$where = NULL;
$column = NULL;
if ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) )
{
$where = array( "contenttypeid=?", static::$postContentType );
$column = 'contentid';
}
else
{
$column = 'postid';
}
foreach( $this->fetch( 'attachment', 'attachmentid', $where ) AS $attachment )
{
try
{
$topic_id = $this->db->select( 'threadid', 'post', array( "postid=?", $attachment[$column] ) )->first();
}
catch( \UnderflowException $e )
{
/* If the topic is missing, there isn't much we can do. */
$libraryClass->setLastKeyValue( $attachment['attachmentid'] );
continue;
}
if ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) )
{
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'] );
continue;
}
}
else
{
$filedata = $attachment;
$filedata['filedataid'] = $attachment['attachmentid'];
}
$map = array(
'id1' => $topic_id,
'id2' => $attachment[$column]
);
$info = array(
'attach_id' => $attachment['attachmentid'],
'attach_file' => $attachment['filename'],
'attach_date' => $attachment['dateline'],
'attach_member_id' => $attachment['userid'],
'attach_hits' => $attachment['counter'],
'attach_ext' => $filedata['extension'],
'attach_filesize' => $filedata['filesize'],
);
if ( $this->app->_session['more_info']['convertAttachments']['file_location'] == 'database' )
{
/* Simples! */
$data = $filedata['filedata'];
$path = NULL;
}
else
{
$data = NULL;
$path = implode( '/', preg_split( '//', $filedata['userid'], -1, PREG_SPLIT_NO_EMPTY ) );
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['file_location'], '/' ) . '/' . $path . '/' . $filedata['filedataid'] . '.attach';
}
$attach_id = $libraryClass->convertAttachment( $info, $map, $path, $data );
/* Do some re-jiggery on the post itself to make sure attachment displays */
if ( $attach_id !== FALSE )
{
try
{
$pid = $this->app->getLink( $attachment[$column], 'forums_posts' );
$post = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->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( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
}
}
catch( \UnderflowException $e ) {}
catch( \OutOfRangeException $e ) {}
}
$libraryClass->setLastKeyValue( $attachment['attachmentid'] );
}
}
/* !vBulletin Stuff */
/**
* @brief Silly Bitwise
*/
public static $bitOptions = array (
'forumoptions' => array(
'active' => 1,
'allowposting' => 2,
'cancontainthreads' => 4,
'moderatenewpost' => 8,
'moderatenewthread' => 16,
'moderateattach' => 32,
'allowbbcode' => 64,
'allowimages' => 128,
'allowhtml' => 256,
'allowsmilies' => 512,
'allowicons' => 1024,
'allowratings' => 2048,
'countposts' => 4096,
'canhavepassword' => 8192,
'indexposts' => 16384,
'styleoverride' => 32768,
'showonforumjump' => 65536,
'prefixrequired' => 131072,
'allowvideos' => 262144,
'bypassdp' => 524288,
'displaywrt' => 1048576,
'canreputation' => 2097152,
),
);
/**
* 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 it looks like a VBSEO URL, rewrite it */
if( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], '.html' ) !== FALSE )
{
/* Paginated topics */
if( preg_match( "/\/(\d+)\-.+?\-(\d+)\.html/", $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$url = $url->setPath( preg_replace( "/\/(\d+)\-.+?\-(\d+)\.html/", "/showthread.php", $url->data[ \IPS\Http\Url::COMPONENT_PATH ] ) )->setQueryString( array( 't' => $matches[1], 'page' => $matches[2] ) );
\IPS\Request::i()->t = $matches[1];
\IPS\Request::i()->page = $matches[2];
}
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];
}
}
/* 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
*/
$path = $url->data[ \IPS\Http\Url::COMPONENT_PATH ];
if( mb_strpos( $path, 'forumdisplay.php' ) !== FALSE )
{
if( isset( \IPS\Request::i()->f ) )
{
$oldId = \IPS\Request::i()->f;
}
else
{
$queryStringPieces = explode( '-', mb_substr( $path, mb_strpos( $path, 'forumdisplay.php/' ) + mb_strlen( 'forumdisplay.php/' ) ) );
$oldId = $queryStringPieces[0];
}
}
if( isset( $oldId ) )
{
try
{
$data = (string) $this->app->getLink( $oldId, array( 'forums', 'forums_forums' ) );
$item = \IPS\forums\Forum::load( $data );
if( $item->can( 'view' ) )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
}
elseif( preg_match( '#/forums/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
try
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'forums', 'forums_forums' ) );
$item = \IPS\forums\Forum::load( $data );
if( $item->can( 'view' ) )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
/* And then post URLs, simple */
elseif(
( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'showthread.php' ) !== FALSE OR
mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'showpost.php' ) !== FALSE OR
preg_match( '#/threads/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ] )
)
AND isset( \IPS\Request::i()->p )
)
{
try
{
try
{
$data = (string) $this->app->getLink( (int) \IPS\Request::i()->p, array( 'posts', 'forums_posts' ) );
}
catch( \OutOfRangeException $e )
{
/* Try the main table */
$data = (string) $this->app->getLink( (int) \IPS\Request::i()->p, array( 'posts', 'forums_posts' ), FALSE, TRUE );
}
$item = \IPS\forums\Topic\Post::load( $data );
if( $item->canView() )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
/* 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
*/
$path = $url->data[ \IPS\Http\Url::COMPONENT_PATH ];
if( mb_strpos( $path, 'showthread.php' ) !== FALSE )
{
if( isset( \IPS\Request::i()->t ) )
{
$oldId = \IPS\Request::i()->t;
}
else
{
$queryStringPieces = explode( '-', mb_substr( $path, mb_strpos( $path, 'showthread.php/' ) + mb_strlen( 'showthread.php/' ) ) );
$oldId = $queryStringPieces[0];
}
}
elseif( preg_match( '#/forums/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$oldId = (int) $matches[1];
}
if( isset( $oldId ) )
{
try
{
try
{
$data = (string) $this->app->getLink( $oldId, array( 'topics', 'forums_topics' ) );
}
catch( \OutOfRangeException $e )
{
/* Try the main table */
$data = (string) $this->app->getLink( $oldId, array( 'topics', 'forums_topics' ), FALSE, TRUE );
}
$item = \IPS\forums\Topic::load( $data );
if( $item->canView() )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
}
elseif( preg_match( '#/threads/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
try
{
try
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'topics', 'forums_topics' ) );
}
catch( \OutOfRangeException $e )
{
/* Try the main table */
$data = (string) $this->app->getLink( (int) $matches[1], array( 'topics', 'forums_topics' ), FALSE, TRUE );
}
$item = \IPS\forums\Topic::load( $data );
if( $item->canView() )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
/* And finally, archives */
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'archive/index.php' ) !== FALSE )
{
$request = str_replace( '/archive/index.php/', '', $_SERVER['REQUEST_URI'] );
$parameters = explode( '-', $request );
$parameters[1] = str_replace( '.html', '', $parameters[1] );
try
{
switch( $parameters[0] )
{
case 't':
try
{
$data = $this->getLink( (string) $parameters[1], array( 'topics', 'forums_topics' ) );
}
catch( \OutOfRangeException $e )
{
$data = $this->getLink( (string) $parameters[1], array( 'topics', 'forums_topics', FALSE, TRUE ) );
}
$item = \IPS\forums\Topic::load( $data );
if( $item->canView() )
{
return $item->url();
}
break;
case 'f':
$data = $this->app->getLink( (string) $parameters[1], array( 'forums', 'forums_forums' ) );
$item = \IPS\forums\Forum::load( $data );
if( $item->can( 'view' ) )
{
return $item->url();
}
break;
}
}
catch( \Exception $e )
{
return NULL;
}
}
return NULL;
}
}
@@ -0,0 +1,733 @@
<?php
/**
* @brief Converter vBulletin 5.x Forums Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 21 Jan 2015
*/
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 _Vbulletin5 extends \IPS\convert\Software
{
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "vBulletin Forums (5.x)";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "vbulletin5";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'forum',
'where' => NULL,
),
'convertForumsTopics' => array(
'table' => 'thread',
'where' => NULL,
),
'convertForumsPosts' => array(
'table' => 'post',
'where' => NULL,
),
'convertAttachments' => array(
'table' => 'attachment',
'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 'forum':
return count( $this->fetchForums() );
break;
case 'thread':
return parent::countRows( 'node', array( \IPS\Db::i()->in( 'contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Poll' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ) ) ) . " AND " . \IPS\Db::i()->in( 'parentid', array_keys( $this->fetchForums() ) ), $this->fetchType( 'Text' ), $this->fetchType( 'Poll' ) ) );
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' ) ) ) ) );
break;
case 'attachment':
return parent::countRows( 'node', array( "contenttypeid=?", $this->fetchType( 'Attach' ) ) );
break;
default:
return parent::countRows( $table, $where, $recache );
break;
}
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'vbulletin5' ) );
}
/**
* 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( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'forums_posts', 'class' => 'IPS\forums\Topic\Post' ), 2, array( 'app', 'link', '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' ) );
return array( 'f_rebuild_posts', 'f_recounting_forums', 'f_recounting_topics' );
}
/**
* Fix Post Data
*
* @param string Post
* @return string Fixed Posts
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\Vbulletin5::fixPostData( $post );
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array( 'convertAttachments' );
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertAttachments':
$return['convertAttachments'] = array(
'file_location' => array(
'field_class' => 'IPS\\Helpers\\Form\\Radio',
'field_default' => 'database',
'field_required' => TRUE,
'field_extra' => array(
'options' => array(
'database' => \IPS\Member::loggedIn()->language()->addToStack( 'database' ),
'file_system' => \IPS\Member::loggedIn()->language()->addToStack( 'file_system' ),
),
'userSuppliedInput' => 'file_system',
),
'field_hint' => NULL,
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
)
);
break;
}
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
}
/**
* Convert forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'node.nodeid' );
foreach( $this->fetch( 'node', 'nodeid', array( "node.nodeid<>? AND closure.parent=? AND node.contenttypeid=?", 2, 2, $this->fetchType( 'Channel' ) ) )->join( 'closure', "closure.child=node.nodeid" ) AS $forum )
{
$self = $this;
$checkpermission = function( $name, $perm ) use ( $forum, $self )
{
$key = $name;
if ( $name == 'forumoptions' )
{
$key = 'nodeoptions';
}
if ( $forum[$key] & $self::$bitOptions[$name][$perm] )
{
return TRUE;
}
return FALSE;
};
$info = array(
'id' => $forum['nodeid'],
'name' => $forum['title'],
'description' => $forum['description'],
'topics' => $forum['textcount'],
'posts' => $forum['totalcount'],
'last_post' => $forum['lastcontent'],
'last_poster_id' => $forum['lastauthorid'],
'last_poster_name' => $forum['lastcontentauthor'],
'parent_id' => $forum['parentid'],
'position' => $forum['displayorder'],
'preview_posts' => $checkpermission( 'forumoptions', 'moderatenewpost' ),
'inc_postcount' => 1,
'forum_allow_rating' => 1,
'sub_can_post' => ( $forum['parentid'] == 2 ) ? 0 : 1,
);
$libraryClass->convertForumsForum( $info );
$libraryClass->setLastKeyValue( $forum['nodeid'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'node.nodeid' );
foreach( $this->fetch( 'node', 'node.nodeid', array( \IPS\Db::i()->in( 'node.parentid', array_keys( $this->fetchForums() ) ) . " AND " . \IPS\Db::i()->in( 'node.contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Poll' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ) ) ) ) )->join( 'text', 'text.nodeid = node.nodeid' ) AS $topic )
{
/* Pesky Polls */
$poll = NULL;
$lastVote = 0;
try
{
/* Does this topic have a corresponding poll? */
$pollData = $this->db->select( '*', 'poll', array( "nodeid=?", $topic['nodeid'] ) )->first();
$pollOptions = @\unserialize( $pollData['options'] );
$lastVote = $pollData['lastvote'];
if ( $pollOptions === FALSE )
{
throw new \UnexpectedValueException;
}
$choices = array();
$numvotes = 0;
$votes = array();
foreach( $pollOptions AS $option )
{
$choices[$option['polloptionid']] = $option['title'];
$votes[$option['polloptionid']] = $option['votes'];
$numvotes += $option['votes'];
}
$poll = array();
$poll['poll_data'] = array(
'pid' => $pollData['nodeid'],
'choices' => array( 1 => array(
'question' => $topic['title'],
'multi' => $pollData['multiple'],
'choice' => $choices,
'votes' => $votes
) ),
'poll_question' => $topic['title'],
'start_date' => $topic['publishdate'],
'starter_id' => $topic['userid'],
'votes' => $numvotes,
'poll_view_voters' => $pollData['public']
);
$poll['vote_data'] = array();
$ourVotes = array();
foreach( $this->db->select( '*', 'pollvote', array( "nodeid=?", $pollData['nodeid'] ) ) AS $vote )
{
if ( !isset( $ourVotes[$vote['userid']] ) )
{
/* Create our structure - vB stores each individual vote as a different row whereas we combine them per user */
$ourVotes[$vote['userid']] = array( 'votes' => array() );
}
$ourVotes[$vote['userid']]['votes'][] = $vote['voteoption'];
/* These don't matter - just use the latest one */
$ourVotes[$vote['userid']]['vid'] = $vote['pollvoteid'];
$ourVotes[$vote['userid']]['vote_date'] = $vote['votedate'];
$ourVotes[$vote['userid']]['member_id'] = $vote['userid'];
}
/* Now we need to re-wrap it all for storage */
foreach( $ourVotes AS $member_id => $vote )
{
$poll['vote_data'][$member_id] = array(
'vid' => $vote['vid'],
'vote_date' => $vote['vote_date'],
'member_id' => $vote['member_id'],
'member_choices' => array( 1 => $vote['votes'] ),
);
}
}
catch( \UnderflowException $e ) {} # if the poll is missing, don't bother
catch( \UnexpectedValueException $e ) {} # if poll data is corrupt, then skip
$info = array(
'tid' => $topic['nodeid'],
'title' => $topic['title'],
'forum_id' => $topic['parentid'],
'state' => $topic['open'] ? 'open' : 'closed',
'posts' => $topic['totalcount'],
'starter_id' => $topic['userid'],
'start_date' => $topic['publishdate'],
'last_poster_id' => $topic['lastauthorid'],
'last_post' => $topic['lastcontent'],
'starter_name' => $topic['authorname'],
'last_poster_name' => $topic['lastcontentauthor'],
'poll_state' => $poll,
'last_vote' => $lastVote,
'approved' => $topic['approved'],
'pinned' => $topic['sticky'],
'topic_open_time' => $topic['publishdate'],
'topic_hiddenposts' => $topic['totalunpubcount']
);
unset( $poll );
$topic_id = $libraryClass->convertForumsTopic( $info );
$libraryClass->setLastKeyValue( $topic['nodeid'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'node.nodeid' );
foreach( $this->fetch( 'node', 'node.nodeid', array( \IPS\Db::i()->in( 'node.contenttypeid', array( $this->fetchType( 'Text' ), $this->fetchType( 'Gallery' ), $this->fetchType( 'Video' ), $this->fetchType( 'Link' ), $this->fetchType( 'Poll' ) ) ) ) )->join( 'text', 'text.nodeid = node.nodeid' ) AS $post )
{
/* Comments of comments of comments of comments */
$isSubComment = FALSE;
try
{
/* Is this the first post? */
$this->app->getLink( $post['parentid'], 'forums_forums' );
$post['parentid'] = $post['nodeid'];
}
catch( \OutOfRangeException $e )
{
try
{
/* If parentid exists as a forums_topics link, we don't actually need to do anything */
$this->app->getLink( $post['parentid'], 'forums_topics' );
}
catch( \OutOfRangeException $e )
{
try
{
$this->app->getLink( $post['parentid'], 'forums_posts' );
$isSubComment = TRUE;
/* Load the parent */
$parent = $this->db->select( '*', 'node', array( "node.nodeid=?", $post['parentid'] ) )->join( 'text', 'text.nodeid = node.nodeid' )->first();
$post['approved'] = $parent['approved'];
$post['parentid'] = $parent['parentid'];
$post['rawtext'] = "[quote name='" . $parent['authorname'] ."' timestamp='" . $parent['created'] . "']" . $parent['rawtext'] . "[/quote]\n" . $post['rawtext'];
}
catch( \OutOfRangeException $e ) # we need to go deeper!
{
/* Actually, we don't - end of the line */
$libraryClass->setLastKeyValue( $post['nodeid'] );
continue;
}
catch( \UnderflowException $e )
{
/* Loading the parent failed - move on */
$libraryClass->setLastKeyValue( $post['nodeid'] );
continue;
}
}
}
$info = array(
'pid' => $post['nodeid'],
'topic_id' => $post['parentid'],
'post' => $post['rawtext'],
'author_id' => $post['userid'],
'author_name' => $post['authorname'],
'ip_address' => $post['ipaddress'],
'post_date' => $post['publishdate'],
'queued' => $post['approved'] ? 0 : -1,
'post_htmlstate' => ( in_array( $post['htmlstate'], array( 'on', 'on_nl2br' ) ) ) ? 1 : 0,
);
$post_id = $libraryClass->convertForumsPost( $info );
/* Reputation */
foreach( $this->db->select( '*', 'reputation', array( "nodeid=?", $post['nodeid'] ) ) AS $rep )
{
$libraryClass->convertReputation( array(
'id' => $rep['reputationid'],
'app' => 'forums',
'type' => 'pid',
'type_id' => $post['nodeid'],
'member_id' => $rep['whoadded'],
'member_received' => $rep['userid'],
'rep_date' => $rep['dateline'],
'rep_rating' => $rep['reputation']
) );
}
/* Edit History */
$latestedit = 0;
$reason = NULL;
$name = NULL;
foreach( $this->db->select( '*', 'postedithistory', array( "nodeid=?", $post['nodeid'] ) ) AS $edit )
{
$libraryClass->convertEditHistory( array(
'id' => $edit['postedithistoryid'],
'class' => 'IPS\\forums\\Topic\\Post',
'comment_id' => $post['nodeid'],
'member' => $edit['userid'],
'time' => $edit['dateline'],
'old' => $edit['pagetext']
) );
if ( $edit['dateline'] > $latestedit )
{
$latestedit = $edit['dateline'];
$reason = $edit['reason'];
$name = $edit['username'];
}
}
/* Warnings */
foreach( $this->db->select( '*', 'infraction', array( "nodeid=?", $post['nodeid'] ) ) AS $warn )
{
$libraryClass->convertWarnLog( array(
'wl_id' => $warn['infractionid'],
'wl_member' => $warn['nodeid'],
'wl_moderator' => $warn['whoadded'],
'wl_date' => $warn['dateline'],
'wl_points' => $warn['points'],
'wl_note_member' => $warn['note'],
'wl_note_mods' => $warn['customreason'],
) );
}
/* 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 */
if ( $latestedit )
{
\IPS\Db::i()->update( 'forums_posts', array( 'append_edit' => 1, 'edit_time' => $latestedit, 'edit_name' => $name, 'post_edit_reason' => $reason ), array( "pid=?", $post_id ) );
}
$libraryClass->setLastKeyValue( $post['nodeid'] );
}
}
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'node.nodeid' );
$main = $this->fetch( 'node', 'node.nodeid', array( "node.contenttypeid=?", $this->fetchType( 'Attach' ) ) )
->join( 'attach', 'attach.nodeid = node.nodeid' )
->join( 'filedata', 'filedata.filedataid = attach.filedataid' );
foreach( $main AS $attachment )
{
try
{
$this->app->getLink( $attachment['parentid'], 'forums_topics' );
$post_id = $attachment['nodeid'];
}
catch( \OutOfRangeException $e )
{
try
{
$this->app->getLink( $attachment['parentid'], 'forums_posts' );
$parent = $this->db->select( 'nodeid, parentid', 'node', array( "nodeid=?", $attachment['parentid'] ) )->first();
$attachment['parentid'] = $parent['parentid'];
$post_id = $parent['nodeid'];
}
catch( \OutOfRangeException $e )
{
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
continue;
}
catch( \UnderflowException $e )
{
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
continue;
}
}
$map = array(
'id1' => $attachment['parentid'],
'id2' => $post_id
);
$info = array(
'attach_id' => $attachment['nodeid'],
'attach_file' => $attachment['filename'],
'attach_date' => $attachment['dateline'],
'attach_member_id' => $attachment['userid'],
'attach_hits' => $attachment['counter'],
'attach_ext' => $attachment['extension'],
'attach_filesize' => $attachment['filesize'],
);
if ( $this->app->_session['more_info']['convertAttachments']['file_location'] == 'database' )
{
/* Simples! */
$data = $attachment['filedata'];
$path = NULL;
}
else
{
$data = NULL;
$path = implode( '/', preg_split( '//', $attachment['userid'], -1, PREG_SPLIT_NO_EMPTY ) );
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['file_location'], '/' ) . '/' . $path . '/' . $attachment['filedataid'] . '.attach';
}
$attach_id = $libraryClass->convertAttachment( $info, $map, $path, $data );
/* Do some re-jiggery on the post itself to make sure attachment displays */
if ( $attach_id !== FALSE )
{
try
{
$pid = $this->app->getLink( $post_id, 'forums_posts' );
$post = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
}
catch( \OutOfRangeException $e )
{
/* If the post didn't exist and this is just an orphaned attachment, move along */
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
continue;
}
if ( preg_match( "/\[ATTACH=(.+?)?\]n" . $attachment['nodeid'] . "\[\/ATTACH\]/i", $post ) )
{
$post = preg_replace( "/\[ATTACH(.+?)?\]" . $attachment['nodeid'] . "\[\/ATTACH\]/i", '[attachment=' . $attach_id . ':name]', $post );
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
}
else
{
$oldAttachId = NULL;
/* Try old attach ID */
try
{
$oldAttachId = $this->db->select( 'attachmentid', 'attachment', array( 'filedataid=?', $attachment['filedataid'] ) )->first();
}
/* Don't fail if this table/value doesn't exist */
catch( \Exception $e ) { }
if ( $oldAttachId !== NULL and preg_match( "/\[ATTACH=(.+?)?\]" . $oldAttachId . "\[\/ATTACH\]/i", $post ) )
{
$post = preg_replace( "/\[ATTACH(.+?)?\]" . $oldAttachId . "\[\/ATTACH\]/i", '[attachment=' . $attach_id . ':name]', $post );
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
}
}
}
$libraryClass->setLastKeyValue( $attachment['nodeid'] );
}
}
/* !vBulletin Stuff */
/**
* @brief Silly Bitwise
*/
public static $bitOptions = array (
'forumoptions' => array(
'active' => 1,
'allowposting' => 2,
'cancontainthreads' => 4,
'moderatenewpost' => 8,
'moderatenewthread' => 16,
'moderateattach' => 32,
'allowbbcode' => 64,
'allowimages' => 128,
'allowhtml' => 256,
'allowsmilies' => 512,
'allowicons' => 1024,
'allowratings' => 2048,
'countposts' => 4096,
'canhavepassword' => 8192,
'indexposts' => 16384,
'styleoverride' => 32768,
'showonforumjump' => 65536,
'prefixrequired' => 131072,
'allowvideos' => 262144,
'bypassdp' => 524288,
'displaywrt' => 1048576,
'canreputation' => 2097152,
),
);
/**
* Helper method to retrieve forums from nodes
*
* @return void
*/
protected function fetchForums()
{
$forums = array();
foreach( $this->db->select( '*', 'node', array( "node.nodeid<>2 AND closure.parent=? AND node.contenttypeid=?", $this->fetchType( 'Thread' ), $this->fetchType( 'Channel' ) ) )->join( 'closure', "closure.child = node.nodeid" ) AS $node )
{
$forums[$node['nodeid']] = $node;
}
return $forums;
}
/**
* @brief Types Cache
*/
protected $typesCache = array();
/**
* Helper method to retrieve content type ids
*
* @return void
*/
protected function fetchType( $type )
{
if ( count( $this->typesCache ) )
{
return $this->typesCache[ $type ];
}
else
{
foreach( $this->db->select( '*', 'contenttype' ) AS $contenttype )
{
$this->typesCache[ $contenttype['class'] ] = $contenttype['contenttypeid'];
}
return $this->typesCache[ $type ];
}
}
/**
* Check if we can redirect the legacy URLs from this software to the new locations
*
* @return NULL|\IPS\Http\Url
* @note Forum URLs do not have IDs in them, so we cannot redirect them reliably
*/
public function checkRedirects()
{
$url = \IPS\Request::i()->url();
if( preg_match( '#(?<!topic)/([0-9]+)\-([^/]*?)#', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
try
{
try
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'topics', 'forums_topics' ) );
}
catch( \OutOfRangeException $e )
{
$data = (string) $this->app->getLink( (int) $matches[1], array( 'topics', 'forums_topics' ), FALSE, TRUE );
}
$item = \IPS\forums\Topic::load( $data );
if( $item->canView() )
{
return $item->url();
}
}
catch( \Exception $e )
{
return NULL;
}
}
return NULL;
}
}
@@ -0,0 +1,716 @@
<?php
/**
* @brief Converter XenForo Class
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @package IPS Community Suite
* @subpackage Converter
* @since 21 Jan 2015
*/
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 _Xenforo extends \IPS\convert\Software
{
/**
* @brief Flag to indicate the post data has been fixed during conversion, and we only need to use Legacy Parser
*/
public static $contentFixed = TRUE;
/**
* Software Name
*
* @return string
*/
public static function softwareName()
{
/* Child classes must override this method */
return "XenForo";
}
/**
* Software Key
*
* @return string
*/
public static function softwareKey()
{
/* Child classes must override this method */
return "xenforo";
}
/**
* Content we can convert from this software.
*
* @return array
*/
public static function canConvert()
{
return array(
'convertForumsForums' => array(
'table' => 'xf_node',
'where' => array( \IPS\Db::i()->in( 'node_type_id', array( 'Category', 'Forum', 'LinkForum' ) ) )
),
'convertForumsTopics' => array(
'table' => 'xf_thread',
'where' => NULL
),
'convertForumsPosts' => array(
'table' => 'xf_post',
'where' => NULL,
),
'convertAttachments' => array(
'table' => 'xf_attachment',
'where' => array( "content_type=?", 'post' )
)
);
}
/**
* Requires Parent
*
* @return boolean
*/
public static function requiresParent()
{
return TRUE;
}
/**
* Possible Parent Conversions
*
* @return array
*/
public static function parents()
{
return array( 'core' => array( 'xenforo' ) );
}
/**
* List of conversion methods that require additional information
*
* @return array
*/
public static function checkConf()
{
return array(
'convertAttachments'
);
}
/**
* Get More Information
*
* @param string $method Conversion method
* @return array
*/
public function getMoreInfo( $method )
{
$return = array();
switch( $method )
{
case 'convertAttachments':
$return['convertAttachments'] = array(
'attach_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_xf_attach_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( '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( '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' ) );
/* 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 raw post data
* @return string parsed post data
*/
public static function fixPostData( $post )
{
return \IPS\convert\Software\Core\Xenforo::fixPostData( $post );
}
/**
* 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 forums
*
* @return void
*/
public function convertForumsForums()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'node_id' );
foreach( $this->fetch( 'xf_node', 'node_id', array( $this->db->in( 'node_type_id', array( 'Category', 'Forum', 'LinkForum' ) ) ) ) AS $row )
{
$data = array();
try
{
switch( $row['node_type_id'] )
{
case 'Forum':
$data = $this->db->select( '*', 'xf_forum', array( "node_id=?", $row['node_id'] ) )->first();
break;
case 'LinkForum':
$data = $this->db->select( '*', 'xf_link_forum', array( "node_id=?", $row['node_id'] ) )->first();
break;
}
}
catch( \UnderflowException $e ) {}
$info = array(
'id' => $row['node_id'],
'name' => $row['title'],
'description' => $row['description'],
'topics' => ( isset( $data['discussion_count'] ) ) ? $data['discussion_count'] : 0,
'posts' => ( isset( $data['message_count'] ) ) ? $data['message_count'] : 0,
'last_post' => ( isset( $data['last_post_date'] ) ) ? $data['last_post_date'] : 0,
'last_poster_id' => ( isset( $data['last_post_user_id'] ) ) ? $data['last_post_user_id'] : 0,
'last_poster_name' => ( isset( $data['last_poster_name'] ) ) ? $data['last_post_username'] : '',
'parent_id' => ( $row['parent_node_id'] == 0 ) ? -1 : $row['parent_node_id'],
'position' => $row['display_order'],
'last_title' => ( isset( $data['last_thread_title'] ) ) ? $data['last_thread_title'] : '',
'allow_poll' => ( isset( $data['allow_poll'] ) ) ? $data['allow_poll'] : 0,
'inc_postcount' => ( isset( $data['count_messages'] ) ) ? $data['count_messages'] : 0,
'redirect_url' => ( isset( $data['link_url'] ) ) ? $data['link_url'] : NULL,
'redirect_on' => ( $row['node_type_id'] == 'LinkForum' ) ? 1 : 0,
'redirect_hits' => ( isset( $data['redirect_count'] ) ) ? $data['redirect_count'] : 0,
'sub_can_post' => ( isset( $data['allow_posting'] ) ) ? $data['allow_posting'] : 0,
);
$libraryClass->convertForumsForum( $info );
/* Follows */
foreach( $this->db->select( '*', 'xf_forum_watch', array( "node_id=? AND notify_on=?", $row['node_id'], 'thread' ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'forum',
'follow_rel_id' => $row['node_id'],
'follow_rel_id_type' => 'forums_forums',
'follow_member_id' => $follow['user_id'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'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
) );
}
$libraryClass->setLastKeyValue( $row['node_id'] );
}
}
/**
* Convert topics
*
* @return void
*/
public function convertForumsTopics()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'thread_id' );
foreach( $this->fetch( 'xf_thread', 'thread_id' ) AS $row )
{
/* Poll */
$poll = NULL;
if ( $row['discussion_type'] == 'poll' )
{
try
{
$poll_data = $this->db->select( '*', 'xf_poll', array( "content_type=? AND content_id=?", 'thread', $row['thread_id'] ) )->first();
$choices = array();
$votes = array();
$index = 1;
foreach( $this->db->select( '*', 'xf_poll_response', array( "poll_id=?", $poll_data['poll_id'] ) ) AS $choice )
{
$choices[$index] = $choice['response'];
$votes[$index] = $choice['response_vote_count'];
$search[$index] = $choice['poll_response_id'];
$index++;
}
$poll['poll_data'] = array(
'pid' => $poll_data['poll_id'],
'choices' => array( 1 => array(
'question' => $poll_data['question'],
'multi' => ( $poll_data['max_votes'] > 1 ) ? 1 : 0,
'choice' => $choices,
'votes' => $votes
) ),
'poll_question' => $poll_data['question'],
'start_date' => $row['post_date'],
'starter_id' => $row['user_id'],
'votes' => array_sum( $votes ),
'poll_view_voters' => $poll_data['public_votes']
);
$poll['vote_data'] = array();
$ourVotes = array();
foreach( $this->db->select( '*', 'xf_poll_vote', array( "poll_id=?", $poll_data['poll_id'] ) ) AS $vote )
{
if ( !isset( $ourVotes[$vote['user_id']] ) )
{
$ourVotes[$vote['user_id']] = array( 'votes' => array() );
}
$ourVotes[$vote['user_id']]['votes'][] = array_search( $vote['poll_response_id'], $search );
$ourVotes[$vote['user_id']]['member_id'] = $vote['user_id'];
}
foreach( $ourVotes AS $member_id => $vote )
{
$poll['vote_data'][$member_id] = array(
'member_id' => $vote['member_id'],
'member_choices' => array( 1 => $vote['votes'] ),
);
}
}
catch( \UnderflowException $e ) {}
}
/* Approval */
switch( $row['discussion_state'] )
{
case 'visible':
$approved = 1;
break;
case 'moderation':
$approved = 0;
break;
case 'deleted':
$approved = -1;
break;
}
/* Moved To */
$moved_to = NULL;
if ( $row['discussion_type'] == 'redirect' )
{
try
{
$redirect = $this->db->select( '*', 'xf_thread_redirect', array( "thread_id=?", $row['thread_id'] ) )->first();
$key = explode( '-', $redirect['redirect_key'] );
$moved_to = array( $key[1], $key[2] );
}
catch( \UnderflowException $e ) {}
}
$info = array(
'tid' => $row['thread_id'],
'title' => $row['title'],
'forum_id' => $row['node_id'],
'state' => ( $row['discussion_open'] ) ? 'open' : 'closed',
'posts' => $row['reply_count'],
'starter_id' => $row['user_id'],
'start_date' => $row['post_date'],
'last_poster_id' => $row['last_post_user_id'],
'last_post' => $row['last_post_date'],
'starter_name' => $row['username'],
'last_poster_name' => $row['last_post_username'],
'poll_state' => $poll,
'views' => $row['view_count'],
'approved' => $approved,
'pinned' => $row['sticky'],
'moved_to' => $moved_to,
);
$libraryClass->convertForumsTopic( $info );
/* Follows */
foreach( $this->db->select( '*', 'xf_thread_watch', array( "thread_id=?", $row['thread_id'] ) ) AS $follow )
{
$libraryClass->convertFollow( array(
'follow_app' => 'forums',
'follow_area' => 'topic',
'follow_rel_id' => $row['thread_id'],
'follow_rel_id_type' => 'forums_topics',
'follow_member_id' => $follow['user_id'],
'follow_is_anon' => 0,
'follow_added' => time(),
'follow_notify_do' => 1,
'follow_notify_meta' => '',
'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']}" );
if ( !is_null( $prefix ) )
{
$libraryClass->convertTag( array(
'tag_meta_app' => 'forums',
'tag_meta_area' => 'forums',
'tag_meta_parent_id' => $row['node_id'],
'tag_meta_id' => $row['thread_id'],
'tag_text' => $prefix,
'tag_member_id' => $row['user_id'],
'tag_prefix' => 1, # key to this whole operation right here
) );
}
}
/* Other tags */
if ( $row['tags'] )
{
$tags = \unserialize( $row['tags'] );
if ( count( $tags ) )
{
foreach( $tags AS $key => $tag )
{
$libraryClass->convertTag( array(
'tag_meta_app' => 'forums',
'tag_meta_area' => 'forums',
'tag_meta_parent_id' => $row['node_id'],
'tag_meta_id' => $row['thread_id'],
'tag_text' => $tag['tag'],
'tag_member_id' => $row['user_id'],
'tag_prefix' => 0
) );
}
}
}
$libraryClass->setLastKeyValue( $row['thread_id'] );
}
}
/**
* Convert posts
*
* @return void
*/
public function convertForumsPosts()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'post_id' );
foreach( $this->fetch( 'xf_post', 'post_id' ) AS $row )
{
/* Query for the IP */
try
{
$ip = $this->db->select( 'ip', 'xf_ip', array( "ip_id=?", $row['ip_id'] ) )->first();
}
catch( \UnderflowException $e )
{
$ip = '127.0.0.1';
}
/* Figure out queued stuff */
try
{
$topic_state = $this->db->select( 'discussion_state', 'xf_thread', array( "thread_id=?", $row['thread_id'] ) )->first();
if ( $topic_state == 'deleted' )
{
$row['message_state'] = 'topic_hidden';
}
}
catch( \UnderflowException $e ) {}
switch( $row['message_state'] )
{
case 'visible':
$queued = 0;
break;
case 'moderated':
$queued = 1;
break;
case 'deleted':
$queued = -1;
break;
case 'topic_hidden':
$queued = 2;
break;
}
$info = array(
'pid' => $row['post_id'],
'topic_id' => $row['thread_id'],
'post' => static::fixPostData( $row['message'] ),
'edit_time' => $row['last_edit_date'],
'author_id' => $row['user_id'],
'author_name' => $row['username'],
'ip_address' => $ip,
'post_date' => $row['post_date'],
'queued' => $queued,
);
$post_id = $libraryClass->convertForumsPost( $info );
/* Reputation */
$likes = \unserialize( $row['like_users'] );
if ( count( $likes ) )
{
foreach( $likes AS $like )
{
$libraryClass->convertReputation( array(
'app' => 'forums',
'type' => 'pid',
'type_id' => $row['post_id'],
'member_id' => $like['user_id'],
'member_received' => $row['user_id'],
) );
}
}
/* Warnings */
foreach( $this->db->select( '*', 'xf_warning', array( "content_type=? AND content_id=?", 'post', $row['post_id'] ) ) AS $warn )
{
$libraryClass->convertWarnLog( array(
'wl_id' => $warn['warning_id'],
'wl_member' => $warn['user_id'],
'wl_moderator' => $warn['warning_user_id'],
'wl_date' => $warn['warning_date'],
'wl_points' => $warn['points'],
'wl_note_member' => $warn['title'],
'wl_note_mods' => $warn['notes'],
) );
}
/* Edit History */
$latestedit = 0;
$reason = NULL;
$name = NULL;
foreach( $this->db->select( '*', 'xf_edit_history', array( "content_type=? AND content_id=?", 'post', $row['post_id'] ) ) AS $edit )
{
$libraryClass->convertEditHistory( array(
'id' => $edit['edit_history_id'],
'class' => 'IPS\\forums\\Topic\\Post',
'comment_id' => $row['post_id'],
'member' => $edit['edit_user_id'],
'time' => $edit['edit_date'],
'old' => $edit['old_text']
) );
if ( $edit['edit_date'] > $latestedit )
{
$latestedit = $edit['edit_date'];
}
}
/* 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 */
if ( $latestedit )
{
\IPS\Db::i()->update( 'forums_posts', array( 'append_edit' => 1, 'edit_time' => $latestedit ), array( "pid=?", $post_id ) );
}
$libraryClass->setLastKeyValue( $row['post_id'] );
}
}
/**
* Convert attachments
*
* @return void
*/
public function convertAttachments()
{
$libraryClass = $this->getLibrary();
$libraryClass::setKey( 'xf_attachment.attachment_id' );
$it = $this->fetch( 'xf_attachment', 'xf_attachment.attachment_id', array( "content_type=?", 'post' ) )->join( 'xf_attachment_data', 'xf_attachment.data_id = xf_attachment_data.data_id' );
foreach( $it AS $row )
{
$topic = $this->db->select( 'thread_id', 'xf_post', array( "post_id=?", $row['content_id'] ) )->first();
$map = array(
'id1' => $topic,
'id2' => $row['content_id'],
);
$ext = explode( '.', $row['filename'] );
$ext = array_pop( $ext );
$info = array(
'attach_id' => $row['attachment_id'],
'attach_file' => $row['filename'],
'attach_date' => $row['upload_date'],
'attach_member_id' => $row['user_id'],
'attach_hits' => $row['view_count'],
'attach_ext' => $ext,
'attach_filesize' => $row['file_size'],
);
$physical_name = $row['data_id'] . '-' . $row['file_hash'] . '.data';
$group = floor( $row['data_id'] / 1000 );
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['attach_location'], '/' ) . '/' . $group . '/' . $physical_name;
$attachId = $libraryClass->convertAttachment( $info, $map, $path );
/* Update Post if we can */
try
{
if ( $attachId !== FALSE )
{
$ourAttachment = \IPS\File::get( 'core_Attachment', \IPS\Db::i()->select( 'attach_location', 'core_attachments', array( 'attach_id=?', $attachId ) )->first() );
$pid = $this->app->getLink( $row['content_id'], 'forums_posts' );
$post = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
if ( preg_match( "/\[ATTACH(.+?)?\]" . $row['attachment_id'] . "\[\/ATTACH\]/i", $post ) )
{
$post = preg_replace( "/\[ATTACH(.+?)?\]" . $row['attachment_id'] . "\[\/ATTACH\]/i", '<p><a href="<fileStore.core_Attachment>/' . (string) $ourAttachment . '" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="' . $attachId . '" src="<fileStore.core_Attachment>/' . (string) $ourAttachment . '" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>', $post );
}
else
{
$post .= '<p><a href="<fileStore.core_Attachment>/' . (string) $ourAttachment . '" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="' . $attachId . '" src="<fileStore.core_Attachment>/' . (string) $ourAttachment . '" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>';
}
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $post ), array( "pid=?", $pid ) );
}
}
catch( \UnderflowException $e ) {}
catch( \OutOfRangeException $e ) {}
$libraryClass->setLastKeyValue( $row['attachment_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( '#/(forums|threads)/(.+?)\.([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$oldId = (int) $matches[3];
switch( $matches[1] )
{
case 'forums':
$class = '\IPS\forums\Forum';
$types = array( 'forums', 'forums_forums' );
break;
case 'threads':
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
break;
}
}
elseif( preg_match( '#/posts/([0-9]+)/#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
{
$class = '\IPS\forums\Topic\Post';
$types = array( 'posts', 'forums_posts' );
$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\Item )
{
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;
}
}