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
@@ -12,16 +12,34 @@
|
||||
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\Phpbb;
|
||||
use IPS\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* PhpBB Forums Converter
|
||||
*/
|
||||
class _Phpbb extends \IPS\convert\Software
|
||||
class Phpbb extends Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
@@ -104,8 +122,8 @@ class _Phpbb extends \IPS\convert\Software
|
||||
{
|
||||
if ( $forum['forum_password'] )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["forum_password_{$forum['forum_id']}"] = \IPS\Member::loggedIn()->language()->addToStack( 'convert_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( 'convert_forum_password_desc' );
|
||||
Member::loggedIn()->language()->words["forum_password_{$forum['forum_id']}"] = Member::loggedIn()->language()->addToStack( 'convert_forum_password', FALSE, array( 'sprintf' => array( $forum['forum_name'] ) ) );
|
||||
Member::loggedIn()->language()->words["forum_password_{$forum['forum_id']}_desc"] = Member::loggedIn()->language()->addToStack( 'convert_forum_password_desc' );
|
||||
|
||||
$return['convertForumsForums']["forum_password_{$forum['forum_id']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Text',
|
||||
@@ -124,8 +142,8 @@ class _Phpbb extends \IPS\convert\Software
|
||||
'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' ); } },
|
||||
'field_hint' => Member::loggedIn()->language()->addToStack('convert_phpbb_attach_path'),
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new DomainException( 'path_invalid' ); } },
|
||||
),
|
||||
);
|
||||
break;
|
||||
@@ -162,24 +180,26 @@ class _Phpbb 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\Phpbb::fixPostData( $post );
|
||||
return Phpbb::fixPostData( $post, $className, $contentId );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,7 +344,7 @@ class _Phpbb extends \IPS\convert\Software
|
||||
{
|
||||
$orphaned = $this->app->getLink( '__global__', 'forums_forums' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
/* Create a forum to store it in */
|
||||
$libraryClass->convertForumsForum( array(
|
||||
@@ -410,13 +430,13 @@ class _Phpbb extends \IPS\convert\Software
|
||||
{
|
||||
$editName = $this->db->select( 'username', 'users', array( 'user_id=?', $row['post_edit_user'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
catch( UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'pid' => $row['post_id'],
|
||||
'topic_id' => $row['topic_id'],
|
||||
'post' => \IPS\convert\Software\Core\Phpbb::stripUid( $row['post_text'], $row['bbcode_uid'] ),
|
||||
'post' => Phpbb::stripUid( $row['post_text'], $row['bbcode_uid'] ),
|
||||
'append_edit' => ( $row['post_edit_user'] ) ? 1 : 0,
|
||||
'edit_time' => $row['post_edit_time'],
|
||||
'edit_name' => $editName,
|
||||
@@ -436,9 +456,9 @@ class _Phpbb extends \IPS\convert\Software
|
||||
try
|
||||
{
|
||||
$log = $this->db->select( '*', 'log', array( "log_id=?", $warning['log_id'] ) )->first();
|
||||
$data = \unserialize( $log['log_data'] );
|
||||
$data = unserialize( $log['log_data'] );
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
$log = array( 'user_id' => 0 );
|
||||
$data = array( 0 => NULL );
|
||||
@@ -513,7 +533,7 @@ class _Phpbb extends \IPS\convert\Software
|
||||
|
||||
if( !isset( $this->_postContent[ $pid ] ) )
|
||||
{
|
||||
$this->_postContent[ $pid ] = \IPS\Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
|
||||
$this->_postContent[ $pid ] = Db::i()->select( 'post', 'forums_posts', array( "pid=?", $pid ) )->first();
|
||||
}
|
||||
|
||||
$attachmentName = preg_quote( $row['real_filename'], '/' );
|
||||
@@ -539,8 +559,8 @@ class _Phpbb extends \IPS\convert\Software
|
||||
$this->_postContent[ $pid ] .= '<br>' . $replacement;
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
catch( \OutOfRangeException $e ) {}
|
||||
catch( UnderflowException $e ) {}
|
||||
catch( OutOfRangeException $e ) {}
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['attach_id'] );
|
||||
@@ -549,49 +569,49 @@ class _Phpbb extends \IPS\convert\Software
|
||||
/* Do the updates */
|
||||
foreach( $this->_postContent as $pid => $content )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $content ), array( 'pid=?', $pid ) );
|
||||
Db::i()->update( 'forums_posts', array( 'post' => $content ), array( 'pid=?', $pid ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$url = \IPS\Request::i()->url();
|
||||
$url = Request::i()->url();
|
||||
|
||||
if( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'viewtopic.php' ) !== FALSE )
|
||||
if( mb_strpos( $url->data[ Url::COMPONENT_PATH ], 'viewtopic.php' ) !== FALSE )
|
||||
{
|
||||
if( isset( \IPS\Request::i()->p ) )
|
||||
if( isset( Request::i()->p ) )
|
||||
{
|
||||
$class = '\IPS\forums\Topic\Post';
|
||||
$types = array( 'posts', 'forums_posts' );
|
||||
$oldId = \IPS\Request::i()->p;
|
||||
$oldId = Request::i()->p;
|
||||
}
|
||||
else
|
||||
{
|
||||
$class = '\IPS\forums\Topic';
|
||||
$types = array( 'topics', 'forums_topics' );
|
||||
$oldId = \IPS\Request::i()->tid ?: \IPS\Request::i()->t;
|
||||
$oldId = Request::i()->tid ?: Request::i()->t;
|
||||
}
|
||||
}
|
||||
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'viewforum.php' ) !== FALSE )
|
||||
elseif( mb_strpos( $url->data[ Url::COMPONENT_PATH ], 'viewforum.php' ) !== FALSE )
|
||||
{
|
||||
$class = '\IPS\forums\Forum';
|
||||
$types = array( 'forums', 'forums_forums' );
|
||||
$oldId = \IPS\Request::i()->f;
|
||||
$oldId = Request::i()->f;
|
||||
}
|
||||
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'download/file.php' ) !== FALSE )
|
||||
elseif( mb_strpos( $url->data[ Url::COMPONENT_PATH ], 'download/file.php' ) !== FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = (string) $this->app->getLink( \IPS\Request::i()->id, array( 'attachments', 'core_attachments' ) );
|
||||
$data = (string) $this->app->getLink( Request::i()->id, array( 'attachments', 'core_attachments' ) );
|
||||
|
||||
return \IPS\Http\Url::external( \IPS\Settings::i()->base_url . 'applications/core/interface/file/attachment.php' )->setQueryString( 'id', $data );
|
||||
return Url::external( Settings::i()->base_url . 'applications/core/interface/file/attachment.php' )->setQueryString( 'id', $data );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -605,20 +625,20 @@ class _Phpbb 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' ) )
|
||||
{
|
||||
@@ -626,7 +646,7 @@ class _Phpbb extends \IPS\convert\Software
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user