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
@@ -11,16 +11,42 @@
|
||||
namespace IPS\convert\Software\Core;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateTimeZone;
|
||||
use erusev\Parsedown;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Content\Search\Index;
|
||||
use IPS\convert\App;
|
||||
use IPS\convert\Software;
|
||||
use IPS\Data\Cache;
|
||||
use IPS\Data\Store;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\IPS;
|
||||
use IPS\Login;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Task;
|
||||
use PasswordHash;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
use function unserialize;
|
||||
use const PATHINFO_BASENAME;
|
||||
use const PATHINFO_DIRNAME;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vanilla Core Converter
|
||||
*/
|
||||
class _Vanilla extends \IPS\convert\Software
|
||||
class Vanilla extends Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
@@ -44,41 +70,6 @@ class _Vanilla extends \IPS\convert\Software
|
||||
return "vanilla";
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The activity type ID for status updates
|
||||
*/
|
||||
protected static $activityStatusType = NULL;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \IPS\convert\App $app The application to reference for database and other information.
|
||||
* @param bool $needDB Establish a DB connection
|
||||
* @return void
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct( \IPS\convert\App $app, $needDB=TRUE )
|
||||
{
|
||||
$return = parent::__construct( $app, $needDB );
|
||||
|
||||
if ( $needDB )
|
||||
{
|
||||
/* What is the activity type ID for status updates? */
|
||||
if ( static::$activityStatusType === NULL )
|
||||
{
|
||||
try
|
||||
{
|
||||
static::$activityStatusType = $this->db->select( 'ActivityTypeID', 'ActivityType',
|
||||
array( 'Name=?', 'Status' ), NULL, 1
|
||||
)->first();
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we convert settings?
|
||||
*
|
||||
@@ -97,7 +88,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
public function settingsMapList()
|
||||
{
|
||||
$settings = array(
|
||||
'fluid' => array( 'title' => \IPS\Member::loggedIn()->language()->addToStack( 'use_fluid_view_convert' ), 'value' => true, 'our_key' => 'use_fluid_view_convert', 'our_title' => \IPS\Member::loggedIn()->language()->addToStack( 'use_fluid_view_convert' ) )
|
||||
'fluid' => array( 'title' => Member::loggedIn()->language()->addToStack( 'use_fluid_view_convert' ), 'value' => true, 'our_key' => 'use_fluid_view_convert', 'our_title' => Member::loggedIn()->language()->addToStack( 'use_fluid_view_convert' ) )
|
||||
);
|
||||
|
||||
return $settings;
|
||||
@@ -116,7 +107,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
return;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => 'fluid' ), array( "conf_key=?", 'forums_default_view' ) );
|
||||
Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => 'fluid' ), array( "conf_key=?", 'forums_default_view' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +116,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
*
|
||||
* @param string $location File location retrieved from the database
|
||||
* @param string $uploadsPath Configured uploads path
|
||||
* @return \IPS\Http\Url|string|void
|
||||
* @return Url|string|void
|
||||
*/
|
||||
public static function parseMediaLocation( $location, $uploadsPath )
|
||||
{
|
||||
@@ -134,7 +125,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
// URL
|
||||
if ( preg_match( '`^https?://`', $location ) )
|
||||
{
|
||||
return \IPS\Http\Url::external( $location );
|
||||
return Url::external( $location );
|
||||
}
|
||||
// Full filesystem path
|
||||
elseif ( mb_strpos( $location, $uploadsPath ) === 0 )
|
||||
@@ -180,11 +171,11 @@ class _Vanilla extends \IPS\convert\Software
|
||||
* Attempt to convert a MySQL datetime string into a unix timestamp
|
||||
*
|
||||
* @param string $date Date(Time) string
|
||||
* @return \IPS\DateTime Timestamp on successful conversion, otherwise NULL
|
||||
* @return DateTime Timestamp on successful conversion, otherwise NULL
|
||||
*/
|
||||
public static function mysqlToDateTime( $date )
|
||||
{
|
||||
return \IPS\DateTime::ts( strtotime( $date ) ?: time() );
|
||||
return DateTime::ts( strtotime( $date ) ?: time() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,10 +194,6 @@ class _Vanilla extends \IPS\convert\Software
|
||||
'table' => 'User',
|
||||
'where' => array( "Deleted<>?", 1 ),
|
||||
),
|
||||
'convertStatuses' => array(
|
||||
'table' => 'Activity',
|
||||
'where' => array( 'ActivityTypeId=?', (int) static::$activityStatusType )
|
||||
),
|
||||
'convertPrivateMessages' => array(
|
||||
'table' => 'Conversation',
|
||||
'where' => NULL
|
||||
@@ -266,15 +253,15 @@ class _Vanilla extends \IPS\convert\Software
|
||||
|
||||
$options = array();
|
||||
$options['none'] = 'None';
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
|
||||
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
|
||||
{
|
||||
$options[ $group->g_id ] = $group->name;
|
||||
}
|
||||
|
||||
foreach( $this->db->select( '*', 'Role' ) AS $group )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['RoleID']}"] = $group['Name'];
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['RoleID']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_group_desc' );
|
||||
Member::loggedIn()->language()->words["map_group_{$group['RoleID']}"] = $group['Name'];
|
||||
Member::loggedIn()->language()->words["map_group_{$group['RoleID']}_desc"] = Member::loggedIn()->language()->addToStack( 'map_group_desc' );
|
||||
|
||||
$return['convertGroups']["map_group_{$group['RoleID']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
@@ -290,13 +277,13 @@ class _Vanilla extends \IPS\convert\Software
|
||||
$return['convertMembers'] = array();
|
||||
|
||||
/* Find out where the photos live */
|
||||
\IPS\Member::loggedIn()->language()->words['attach_location_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'attach_location' );
|
||||
Member::loggedIn()->language()->words['attach_location_desc'] = Member::loggedIn()->language()->addToStack( 'attach_location' );
|
||||
$return['convertMembers']['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_hint' => Member::loggedIn()->language()->addToStack('convert_vanilla_photopath'),
|
||||
);
|
||||
break;
|
||||
}
|
||||
@@ -312,28 +299,25 @@ class _Vanilla extends \IPS\convert\Software
|
||||
public function finish()
|
||||
{
|
||||
/* Search Index Rebuild */
|
||||
\IPS\Content\Search\Index::i()->rebuild();
|
||||
Index::i()->rebuild();
|
||||
|
||||
/* Clear Cache and Store */
|
||||
\IPS\Data\Store::i()->clearAll();
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
/* Content Rebuilds */
|
||||
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'core_member_status_updates', 'class' => 'IPS\core\Statuses\Status' ), 2, array( 'app', 'link', 'class' ) );
|
||||
Store::i()->clearAll();
|
||||
Cache::i()->clearAll();
|
||||
|
||||
/* Non-Content Rebuilds */
|
||||
\IPS\Task::queue( 'convert', 'RebuildProfilePhotos', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_message_posts', 'extension' => 'core_Messaging' ), 2, array( 'app', 'link', 'extension' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_members', 'extension' => 'core_Signatures' ), 2, array( 'app', 'link', 'extension' ) );
|
||||
Task::queue( 'convert', 'RebuildProfilePhotos', array( 'app' => $this->app->app_id ), 5, array( 'app' ) );
|
||||
Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_message_posts', 'extension' => 'core_Messaging' ), 2, array( 'app', 'link', 'extension' ) );
|
||||
Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_members', 'extension' => 'core_Signatures' ), 2, array( 'app', 'link', 'extension' ) );
|
||||
|
||||
/* Content Counts */
|
||||
\IPS\Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
|
||||
Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
|
||||
|
||||
/* First Post Data */
|
||||
\IPS\Task::queue( 'convert', 'RebuildConversationFirstIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
|
||||
Task::queue( 'convert', 'RebuildConversationFirstIds', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
|
||||
|
||||
/* Attachments */
|
||||
\IPS\Task::queue( 'core', 'RebuildAttachmentThumbnails', array( 'app' => $this->app->app_id ), 1, array( 'app' ) );
|
||||
Task::queue( 'core', 'RebuildAttachmentThumbnails', array( 'app' => $this->app->app_id ), 1, array( 'app' ) );
|
||||
|
||||
return array( "f_search_index_rebuild", "f_clear_caches", "f_rebuild_pms", "f_signatures_rebuild", "f_rebuild_attachments" );
|
||||
}
|
||||
@@ -344,12 +328,14 @@ class _Vanilla extends \IPS\convert\Software
|
||||
protected static $_parseDown = NULL;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
/* Is this Markdown? */
|
||||
if( mb_substr( $post, 0, 15 ) == '<!--Markdown-->' )
|
||||
@@ -357,8 +343,8 @@ class _Vanilla extends \IPS\convert\Software
|
||||
/* Load parser */
|
||||
if( static::$_parseDown === NULL )
|
||||
{
|
||||
\IPS\IPS::$PSR0Namespaces['erusev'] = \IPS\ROOT_PATH . "/applications/convert/sources/Tools/Vanilla/Parsedown";
|
||||
static::$_parseDown = new \erusev\Parsedown();
|
||||
IPS::$PSR0Namespaces['erusev'] = \IPS\ROOT_PATH . "/applications/convert/sources/Tools/Vanilla/Parsedown";
|
||||
static::$_parseDown = new Parsedown();
|
||||
}
|
||||
|
||||
$post = str_replace( '<!--Markdown-->', '', $post );
|
||||
@@ -372,7 +358,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
$post = '';
|
||||
foreach( $postData as $data )
|
||||
{
|
||||
if( \is_array( $data['insert'] ) )
|
||||
if( is_array( $data['insert'] ) )
|
||||
{
|
||||
switch ( $data['insert']['embed-external']['data']['embedType'] )
|
||||
{
|
||||
@@ -392,11 +378,11 @@ class _Vanilla extends \IPS\convert\Software
|
||||
$matches = [];
|
||||
preg_match_all( '/@("|")([^@"]+)("|")/i', $post, $matches );
|
||||
|
||||
if( \count( $matches ) )
|
||||
if( count( $matches ) )
|
||||
{
|
||||
foreach( $matches[0] as $key => $tag )
|
||||
{
|
||||
$member = \IPS\Member::load( $matches[2][ $key ], 'name' );
|
||||
$member = Member::load( $matches[2][ $key ], 'name' );
|
||||
if( !$member->member_id )
|
||||
{
|
||||
continue;
|
||||
@@ -454,7 +440,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
}
|
||||
|
||||
/* Now check for group promotions */
|
||||
if( \count( $libraryClass->groupPromotions ) )
|
||||
if( count( $libraryClass->groupPromotions ) )
|
||||
{
|
||||
foreach( $libraryClass->groupPromotions as $groupPromotion )
|
||||
{
|
||||
@@ -488,8 +474,8 @@ class _Vanilla extends \IPS\convert\Software
|
||||
$bdayMonth = NULL;
|
||||
$bdayYear = NULL;
|
||||
|
||||
$dateOfBirth = !empty( $row['DateOfBirth'] ) ? @\IPS\DateTime::ts( strtotime( $row['DateOfBirth'] ) ) : NULL;
|
||||
if ( $dateOfBirth instanceof \IPS\DateTime )
|
||||
$dateOfBirth = !empty( $row['DateOfBirth'] ) ? @DateTime::ts( strtotime( $row['DateOfBirth'] ) ) : NULL;
|
||||
if ( $dateOfBirth instanceof DateTime )
|
||||
{
|
||||
$bdayYear = $dateOfBirth->format( 'Y' );
|
||||
$bdayMonth = $dateOfBirth->format( 'n' );
|
||||
@@ -517,7 +503,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
'last_visit' => static::mysqlToDateTime( $row['DateLastActive'] ),
|
||||
'timezone' => !empty( $row['HourOffset'] )
|
||||
? (int) $row['HourOffset']
|
||||
: new \DateTimeZone(
|
||||
: new DateTimeZone(
|
||||
'UTC'
|
||||
),
|
||||
'member_posts' => (int) $row['CountComments'],
|
||||
@@ -529,7 +515,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
|
||||
if ( !empty( $row['Photo'] ) AND ( $location = static::parseMediaLocation( $row['Photo'], $uploadsPath ) ) )
|
||||
{
|
||||
if ( $location instanceof \IPS\Http\Url )
|
||||
if ( $location instanceof Url )
|
||||
{
|
||||
/* The library uses file_get_contents() so we can just pop the file name off and pass the URL directly */
|
||||
$filebits = explode( '/', (string) $location );
|
||||
@@ -539,8 +525,8 @@ class _Vanilla extends \IPS\convert\Software
|
||||
else
|
||||
{
|
||||
// Full-sized profile photos start with "p", small profile photos start with "n"
|
||||
$filename = 'p' . pathinfo( $location, \PATHINFO_BASENAME );
|
||||
$filepath = pathinfo( $location, \PATHINFO_DIRNAME );
|
||||
$filename = 'p' . pathinfo( $location, PATHINFO_BASENAME );
|
||||
$filepath = pathinfo( $location, PATHINFO_DIRNAME );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -551,37 +537,6 @@ class _Vanilla extends \IPS\convert\Software
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert statuses
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertStatuses()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'ActivityID' );
|
||||
|
||||
$data = iterator_to_array( $this->fetch( 'Activity', 'ActivityID', array( 'ActivityTypeID=?', static::$activityStatusType ) ) );
|
||||
$this->app->preCacheLinks( $data, [ 'core_members' => 'ActivityUserID' ] );
|
||||
|
||||
/* Run conversions */
|
||||
foreach ( $data as $row )
|
||||
{
|
||||
$info = array(
|
||||
'status_id' => $row['ActivityID'],
|
||||
'status_member_id' => $row['ActivityUserID'],
|
||||
'status_date' => \IPS\DateTime::ts( strtotime( $row['DateInserted'] ) ?: time() ),
|
||||
'status_content' => $row['Story'],
|
||||
//'status_replies' => $this->countRows( 'ActivityComment', array( 'ActivityID=?', $row['ActivityID'] ) ),
|
||||
'status_author_id' => $row['ActivityUserID'],
|
||||
'status_author_ip' => $row['InsertIPAddress'],
|
||||
);
|
||||
|
||||
$libraryClass->convertStatus( $info );
|
||||
$libraryClass->setLastKeyValue( $row['ActivityID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PMs
|
||||
*
|
||||
@@ -606,7 +561,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
'mt_date' => static::mysqlToDateTime( $row['DateInserted'] ),
|
||||
'mt_starter_id' => $row['InsertUserID'],
|
||||
'mt_last_post_time' => static::mysqlToDateTime( $row['DateUpdated'] ),
|
||||
'mt_to_count' => ( isset( $row['CountParticipants'] ) ) ? $row['CountParticipants'] : \count( \unserialize( $row['Contributors'] ) ),
|
||||
'mt_to_count' => ( isset( $row['CountParticipants'] ) ) ? $row['CountParticipants'] : count( unserialize( $row['Contributors'] ) ),
|
||||
'mt_replies' => $row['CountMessages'],
|
||||
);
|
||||
|
||||
@@ -667,7 +622,7 @@ class _Vanilla extends \IPS\convert\Software
|
||||
/**
|
||||
* Process a login
|
||||
*
|
||||
* @param \IPS\Member $member The member
|
||||
* @param Member $member The member
|
||||
* @param string $password Password from form
|
||||
* @return bool
|
||||
*/
|
||||
@@ -677,11 +632,11 @@ class _Vanilla extends \IPS\convert\Software
|
||||
if( preg_match( '/^\$2[ay]\$(0[4-9]|[1-2][0-9]|3[0-1])\$[a-zA-Z0-9.\/]{53}/', $member->conv_password ) OR mb_substr( $member->conv_password, 0, 3 ) == '$P$' )
|
||||
{
|
||||
require_once \IPS\ROOT_PATH . "/applications/convert/sources/Login/PasswordHash.php";
|
||||
$ph = new \PasswordHash( 8, TRUE );
|
||||
$ph = new PasswordHash( 8, TRUE );
|
||||
return $ph->CheckPassword( $password, $member->conv_password ) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
if ( \IPS\Login::compareHashes( $member->conv_password, md5( md5( str_replace( ''', "'", html_entity_decode( $password ) ) ) . $member->misc ) ) )
|
||||
if ( Login::compareHashes( $member->conv_password, md5( md5( str_replace( ''', "'", html_entity_decode( $password ) ) ) . $member->misc ) ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user