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,35 @@
|
||||
namespace IPS\convert\Software\Forums;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Content;
|
||||
use IPS\convert\Software;
|
||||
use IPS\convert\Software\Core\Wpforo;
|
||||
use IPS\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Request;
|
||||
use IPS\Task;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function stristr;
|
||||
use function strtotime;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* wpForo Forums Converter
|
||||
*/
|
||||
class _Wpforo extends \IPS\convert\Software
|
||||
class Wpforo extends Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
@@ -100,31 +119,33 @@ class _Wpforo 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' ) );
|
||||
|
||||
/* Rebuild Leaderboard */
|
||||
\IPS\Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
|
||||
\IPS\Db::i()->delete( 'core_reputation_leaderboard_history' );
|
||||
Task::queue( 'core', 'RebuildReputationLeaderboard', array(), 4 );
|
||||
Db::i()->delete( 'core_reputation_leaderboard_history' );
|
||||
|
||||
/* Caches */
|
||||
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'forums_topics', 'class' => 'IPS\forums\Topic' ), 3, array( 'app', 'link', 'class' ) );
|
||||
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
|
||||
* Pre-process content for the Invision Community text parser
|
||||
*
|
||||
* @param string $post Post
|
||||
* @return string Fixed Post
|
||||
* @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\Wpforo::fixPostData( $post );
|
||||
return Wpforo::fixPostData( $post, $className, $contentId );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,10 +175,10 @@ class _Wpforo extends \IPS\convert\Software
|
||||
/* Get our reactions to let the admin map them */
|
||||
$options = [];
|
||||
$descriptions = [];
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_reactions' ), 'IPS\Content\Reaction' ) AS $reaction )
|
||||
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'core_reactions' ), 'IPS\Content\Reaction' ) AS $reaction )
|
||||
{
|
||||
$options[ $reaction->id ] = $reaction->_icon->url;
|
||||
$descriptions[ $reaction->id ] = \IPS\Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id ) . '<br>' . $reaction->_description;
|
||||
$descriptions[ $reaction->id ] = Member::loggedIn()->language()->addToStack('reaction_title_' . $reaction->id ) . '<br>' . $reaction->_description;
|
||||
}
|
||||
|
||||
$return['convertForumsPosts'] = [
|
||||
@@ -248,7 +269,7 @@ class _Wpforo extends \IPS\convert\Software
|
||||
'forum_id' => $row['forumid'],
|
||||
'state' => ( $row['closed'] == 1 ) ? 'closed' : 'open',
|
||||
'starter_id' => $row['userid'],
|
||||
'start_date' => \strtotime( $row['created'] ),
|
||||
'start_date' => strtotime( $row['created'] ),
|
||||
'posts' => $row['posts'],
|
||||
'views' => $row['views'],
|
||||
'approved' => $row['private'] ? 0 : 1
|
||||
@@ -315,9 +336,9 @@ class _Wpforo extends \IPS\convert\Software
|
||||
'pid' => $row['postid'],
|
||||
'topic_id' => $row['topicid'],
|
||||
'post' => $row['body'],
|
||||
'edit_time' => $row['modified'] != $row['created'] ? \strtotime( $row['modified'] ) : null,
|
||||
'edit_time' => $row['modified'] != $row['created'] ? strtotime( $row['modified'] ) : null,
|
||||
'author_id' => $row['userid'],
|
||||
'post_date' => \strtotime( $row['created'] ),
|
||||
'post_date' => strtotime( $row['created'] ),
|
||||
'queued' => $row['private'] ? 1 : 0,
|
||||
];
|
||||
|
||||
@@ -359,7 +380,7 @@ class _Wpforo extends \IPS\convert\Software
|
||||
|
||||
foreach( $this->fetch( 'wpforo_posts', 'postid' ) AS $row )
|
||||
{
|
||||
if( !\stristr( $row['body'], '[attach]' ) AND !\stristr( $row['body'], 'wpforo-attached-file' ) )
|
||||
if( !stristr( $row['body'], '[attach]' ) AND !stristr( $row['body'], 'wpforo-attached-file' ) )
|
||||
{
|
||||
$libraryClass->setLastKeyValue( $row['postid'] );
|
||||
continue;
|
||||
@@ -374,7 +395,7 @@ class _Wpforo extends \IPS\convert\Software
|
||||
$matches = [];
|
||||
preg_match_all( '/\[attach\](\d+)\[\/attach\]/i', $row['body'], $matches );
|
||||
|
||||
if( \count( $matches ) )
|
||||
if( count( $matches ) )
|
||||
{
|
||||
foreach( $matches[1] as $key => $id )
|
||||
{
|
||||
@@ -385,7 +406,7 @@ class _Wpforo extends \IPS\convert\Software
|
||||
$info = [
|
||||
'attach_id' => $row['postid'],
|
||||
'attach_file' => $sourceAttachment['filename'],
|
||||
'attach_date' => \strtotime( $row['created'] ),
|
||||
'attach_date' => strtotime( $row['created'] ),
|
||||
'attach_member_id' => $sourceAttachment['userid'],
|
||||
'attach_filesize' => $sourceAttachment['size'],
|
||||
];
|
||||
@@ -404,14 +425,14 @@ class _Wpforo 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();
|
||||
}
|
||||
|
||||
$this->_postContent[ $pid ] = str_replace( $matches[0][ $key ], '[attachment=' . $attachId . ':name]', $this->_postContent[ $pid ] );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
catch( \OutOfRangeException $e ) {}
|
||||
catch( UnderflowException $e ) {}
|
||||
catch( OutOfRangeException $e ) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,7 +440,7 @@ class _Wpforo extends \IPS\convert\Software
|
||||
$matches = [];
|
||||
preg_match_all( '/\<div id\="wpfa\-[\d]+"(.+?)?>\<a class\="wpforo\-default\-attachment" href\="(.+?)"(.+?)?>\<i class\="(.+?)">\<\/i>(.+?)<\/a><\/div>/i', $row['body'], $matches );
|
||||
|
||||
if( \count( $matches ) )
|
||||
if( count( $matches ) )
|
||||
{
|
||||
foreach( $matches[2] as $key => $url )
|
||||
{
|
||||
@@ -428,7 +449,7 @@ class _Wpforo extends \IPS\convert\Software
|
||||
$info = [
|
||||
'attach_id' => $row['postid'],
|
||||
'attach_file' => $filename,
|
||||
'attach_date' => \strtotime( $row['created'] ),
|
||||
'attach_date' => strtotime( $row['created'] ),
|
||||
'attach_member_id' => $row['userid'],
|
||||
];
|
||||
|
||||
@@ -446,14 +467,14 @@ class _Wpforo 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();
|
||||
}
|
||||
|
||||
$this->_postContent[ $pid ] = str_replace( $matches[0][ $key ], '[attachment=' . $attachId . ':name]', $this->_postContent[ $pid ] );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
catch( \OutOfRangeException $e ) {}
|
||||
catch( UnderflowException $e ) {}
|
||||
catch( OutOfRangeException $e ) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,28 +484,28 @@ class _Wpforo extends \IPS\convert\Software
|
||||
/* Do the updates */
|
||||
foreach( $this->_postContent as $id => $content )
|
||||
{
|
||||
\IPS\Db::i()->update( 'forums_posts', array( 'post' => $content ), array( 'pid=?', $id ) );
|
||||
Db::i()->update( 'forums_posts', array( 'post' => $content ), array( 'pid=?', $id ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we can redirect the legacy URLs from this software to the new locations
|
||||
*
|
||||
* @return NULL|\IPS\Http\Url
|
||||
* @return NULL|Url
|
||||
*/
|
||||
public function checkRedirects()
|
||||
{
|
||||
$url = \IPS\Request::i()->url();
|
||||
$wpForoSlug = \defined('WPFORO_SLUG') ? WPFOROSLUG : 'community';
|
||||
$url = Request::i()->url();
|
||||
$wpForoSlug = defined('WPFORO_SLUG') ? WPFOROSLUG : 'community';
|
||||
|
||||
$matches = [];
|
||||
if( preg_match( '#/' . $wpForoSlug . '/([a-z0-9-]+)/([a-z0-9-]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
|
||||
if( preg_match( '#/' . $wpForoSlug . '/([a-z0-9-]+)/([a-z0-9-]+)#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
|
||||
{
|
||||
$class = '\IPS\forums\Topic';
|
||||
$types = [ 'topic_furl' ];
|
||||
$oldId = $matches[2];
|
||||
}
|
||||
elseif( preg_match( '#/' . $wpForoSlug . '/([a-z0-9-]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
|
||||
elseif( preg_match( '#/' . $wpForoSlug . '/([a-z0-9-]+)#i', $url->data[ Url::COMPONENT_PATH ], $matches ) )
|
||||
{
|
||||
$class = '\IPS\forums\Forum';
|
||||
$types = [ 'forum_furl' ];
|
||||
@@ -499,20 +520,20 @@ class _Wpforo 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' ) )
|
||||
{
|
||||
@@ -520,7 +541,7 @@ class _Wpforo extends \IPS\convert\Software
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user