Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -13,16 +13,36 @@
|
||||
namespace IPS\convert\Software\Forums;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use Exception;
|
||||
use IPS\Content;
|
||||
use IPS\convert\Software;
|
||||
use IPS\convert\Software\Core\Smf;
|
||||
use IPS\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Request;
|
||||
use IPS\Task;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function chr;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
use function is_null;
|
||||
use function unserialize;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* SMF Forums Converter
|
||||
*/
|
||||
class _Smf extends \IPS\convert\Software
|
||||
class Smf extends Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
@@ -89,7 +109,7 @@ class _Smf extends \IPS\convert\Software
|
||||
$rows['convertForumsBoards'] = array(
|
||||
'step_title' => 'convert_forums_forums',
|
||||
'step_method' => 'convertForumsBoards',
|
||||
'ips_rows' => \IPS\Db::i()->select( 'COUNT(*)', 'forums_forums' ),
|
||||
'ips_rows' => Db::i()->select( 'COUNT(*)', 'forums_forums' ),
|
||||
'source_rows' => array( 'table' => static::canConvert()['convertForumsBoards']['table'], 'where' => static::canConvert()['convertForumsBoards']['where'] ),
|
||||
'per_cycle' => 200,
|
||||
'dependencies' => array( 'convertForumsForums' ),
|
||||
@@ -117,9 +137,9 @@ class _Smf extends \IPS\convert\Software
|
||||
{
|
||||
return $this->db->select( 'COUNT(*)', 'categories' )->first() + $this->db->select( 'COUNT(*)', 'boards' )->first();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
throw new \IPS\convert\Exception( sprintf( \IPS\Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
|
||||
throw new \IPS\convert\Exception( sprintf( Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -180,8 +200,8 @@ class _Smf extends \IPS\convert\Software
|
||||
'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' ); } },
|
||||
'field_hint' => Member::loggedIn()->language()->addToStack('convert_smf_attach_path'),
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
|
||||
),
|
||||
);
|
||||
break;
|
||||
@@ -198,24 +218,26 @@ class _Smf extends \IPS\convert\Software
|
||||
public function finish()
|
||||
{
|
||||
/* Content Rebuilds */
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\forums\Forum', 'count' => 0 ), 4, array( 'class' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'forums_posts', 'class' => 'IPS\forums\Topic\Post' ), 2, array( 'app', 'link', 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\forums\Topic' ), 3, array( 'class' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildFirstPostIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
|
||||
\IPS\Task::queue( 'convert', 'DeleteEmptyTopics', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
|
||||
Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\forums\Forum', 'count' => 0 ), 4, array( 'class' ) );
|
||||
Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'forums_posts', 'class' => 'IPS\forums\Topic\Post' ), 2, array( 'app', 'link', 'class' ) );
|
||||
Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\forums\Topic' ), 3, array( 'class' ) );
|
||||
Task::queue( 'convert', 'RebuildFirstPostIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
|
||||
Task::queue( 'convert', 'DeleteEmptyTopics', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
|
||||
|
||||
return array( "f_forum_last_post_data", "f_rebuild_posts", "f_recounting_forums", "f_recounting_topics" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fix post data
|
||||
* Pre-process content for the Invision Community text parser
|
||||
*
|
||||
* @param string $post Raw post data
|
||||
* @return string Parsed post data
|
||||
* @param string The post
|
||||
* @param string|null Content Classname passed by post-conversion rebuild
|
||||
* @param int|null Content ID passed by post-conversion rebuild
|
||||
* @return string The converted post
|
||||
*/
|
||||
public static function fixPostData( $post )
|
||||
public static function fixPostData( string $post, ?string $className=null, ?int $contentId=null ): string
|
||||
{
|
||||
return \IPS\convert\Software\Core\Smf::fixPostData( $post );
|
||||
return Smf::fixPostData( $post, $className, $contentId );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,7 +288,7 @@ class _Smf extends \IPS\convert\Software
|
||||
$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 ) {}
|
||||
catch( UnderflowException $e ) {}
|
||||
|
||||
$info = array(
|
||||
'id' => $row['id_board'],
|
||||
@@ -309,7 +331,7 @@ class _Smf extends \IPS\convert\Software
|
||||
{
|
||||
$firstPost = $this->db->select( '*', 'messages', array( "id_msg=?", $row['id_first_msg'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
$libraryClass->setLastKeyValue( $row['id_topic'] );
|
||||
continue;
|
||||
@@ -320,7 +342,7 @@ class _Smf extends \IPS\convert\Software
|
||||
{
|
||||
$lastPost = $this->db->select( '*', 'messages', array( "id_msg=?", $row['id_last_msg'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
catch( UnderflowException $e ) {}
|
||||
|
||||
$poll = NULL;
|
||||
if ( $row['id_poll'] )
|
||||
@@ -330,23 +352,21 @@ class _Smf extends \IPS\convert\Software
|
||||
$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 = $votes = $search = [];
|
||||
$index = 1;
|
||||
|
||||
$choices = array();
|
||||
$votes = 0;
|
||||
foreach( $options AS $option )
|
||||
{
|
||||
$choices[ $index ] = $option['label'];
|
||||
$votes[ $index ] = $option['votes'];
|
||||
$search[ $index ] = $option['id_choice'];
|
||||
$index++;
|
||||
$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_votes[$vote['id_member']] = array(
|
||||
'member_id' => $vote['id_member'],
|
||||
'member_choices' => array( 1 => array_search( $vote['id_choice'], $search ) )
|
||||
'member_choices' => array( $vote['id_choice'] )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -366,7 +386,7 @@ class _Smf extends \IPS\convert\Software
|
||||
'vote_data' => $member_votes
|
||||
);
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
catch( UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
$info = array(
|
||||
@@ -455,19 +475,19 @@ class _Smf extends \IPS\convert\Software
|
||||
*/
|
||||
public function convertAttachments()
|
||||
{
|
||||
if ( \is_null( static::$paths ) )
|
||||
if ( is_null( static::$paths ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
static::$paths = @\unserialize( $this->db->select( 'value', 'settings', array( "variable=?", 'attachmentUploadDir' ) )->first() );
|
||||
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 ) )
|
||||
if ( !is_array( static::$paths ) )
|
||||
{
|
||||
static::$paths = array();
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
static::$paths = array();
|
||||
}
|
||||
@@ -483,7 +503,7 @@ class _Smf extends \IPS\convert\Software
|
||||
{
|
||||
$post = $this->db->select( 'id_topic, poster_time', 'messages', array( "id_msg=?", $row['id_msg'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
$libraryClass->setLastKeyValue( $row['id_attach'] );
|
||||
continue;
|
||||
@@ -523,8 +543,8 @@ class _Smf extends \IPS\convert\Software
|
||||
$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']);
|
||||
$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(
|
||||
@@ -587,36 +607,36 @@ class _Smf extends \IPS\convert\Software
|
||||
/**
|
||||
* Check if we can redirect the legacy URLs from this software to the new locations
|
||||
*
|
||||
* @return NULL|\IPS\Http\Url
|
||||
* @return NULL|Url
|
||||
*/
|
||||
public function checkRedirects()
|
||||
{
|
||||
/* Support SMF friendly URLs ( index.php/topic,1000.0.html ) */
|
||||
$url = \IPS\Request::i()->url();
|
||||
if( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'topic,' ) !== FALSE )
|
||||
$url = Request::i()->url();
|
||||
if( mb_strpos( $url->data[ Url::COMPONENT_PATH ], 'topic,' ) !== FALSE )
|
||||
{
|
||||
\IPS\Request::i()->topic = (int) explode( ',', $url->data[ \IPS\Http\Url::COMPONENT_PATH ] )[1];
|
||||
Request::i()->topic = (int) explode( ',', $url->data[ Url::COMPONENT_PATH ] )[1];
|
||||
}
|
||||
|
||||
if( isset( \IPS\Request::i()->topic ) )
|
||||
if( isset( Request::i()->topic ) )
|
||||
{
|
||||
if( mb_strpos( \IPS\Request::i()->topic, '.msg' ) !== FALSE )
|
||||
if( mb_strpos( 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 );
|
||||
$oldId = mb_substr( Request::i()->topic, mb_strpos( Request::i()->topic, '.msg' ) + 4 );
|
||||
}
|
||||
else
|
||||
{
|
||||
$pieces = explode( '.', \IPS\Request::i()->topic );
|
||||
$pieces = explode( '.', Request::i()->topic );
|
||||
$class = '\IPS\forums\Topic';
|
||||
$types = array( 'topics', 'forums_topics' );
|
||||
$oldId = $pieces[0];
|
||||
}
|
||||
}
|
||||
elseif( isset( \IPS\Request::i()->board ) )
|
||||
elseif( isset( Request::i()->board ) )
|
||||
{
|
||||
$pieces = explode( '.', \IPS\Request::i()->board );
|
||||
$pieces = explode( '.', Request::i()->board );
|
||||
$class = '\IPS\forums\Forum';
|
||||
$types = array( 'forums', 'forums_forums' );
|
||||
$oldId = $pieces[0];
|
||||
@@ -630,20 +650,20 @@ class _Smf extends \IPS\convert\Software
|
||||
{
|
||||
$data = (string) $this->app->getLink( $oldId, $types );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
$data = (string) $this->app->getLink( $oldId, $types, FALSE, TRUE );
|
||||
}
|
||||
$item = $class::load( $data );
|
||||
|
||||
if( $item instanceof \IPS\Content )
|
||||
if( $item instanceof Content )
|
||||
{
|
||||
if( $item->canView() )
|
||||
{
|
||||
return $item->url();
|
||||
}
|
||||
}
|
||||
elseif( $item instanceof \IPS\Node\Model )
|
||||
elseif( $item instanceof Model )
|
||||
{
|
||||
if( $item->can( 'view' ) )
|
||||
{
|
||||
@@ -651,7 +671,7 @@ class _Smf extends \IPS\convert\Software
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user