Version 4.1.19.4
This commit is contained in:
1 parent
2bd5025018
commit
0dc2aee5ed
312 files changed
+53730
-32118
No files matched your search
@@ -0,0 +1,622 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter vBulletin 4.x Blog 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\Blog;
|
||||
|
||||
/* 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 blog app.
|
||||
*/
|
||||
protected static $entryContentType = 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;
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
/* Is this vB3 or vB4? */
|
||||
try
|
||||
{
|
||||
if ( static::$isLegacy === NULL AND $needDB )
|
||||
{
|
||||
$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::$entryContentType === NULL AND ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) ) AND $needDB )
|
||||
{
|
||||
static::$entryContentType = $this->db->select( 'contenttypeid', 'contenttype', array( "class=?", 'BlogEntry' ) )->first();
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "vBulletin Blog (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()
|
||||
{
|
||||
$attachmentTable = 'blog_attachment';
|
||||
$attachmentWhere = NULL;
|
||||
if ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) )
|
||||
{
|
||||
$attachmentTable = 'attachment';
|
||||
$attachmentWhere = array( "contenttypeid=?", static::$entryContentType );
|
||||
}
|
||||
|
||||
return array(
|
||||
'convertBlogs' => array(
|
||||
'table' => 'blog_user',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertBlogEntries' => array(
|
||||
'table' => 'blog',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertBlogComments' => array(
|
||||
'table' => 'blog_text',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertAttachments' => array(
|
||||
'table' => $attachmentTable,
|
||||
'where' => $attachmentWhere
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
default:
|
||||
return parent::countRows( $table, $where );
|
||||
break;
|
||||
|
||||
case 'blog_text':
|
||||
return parent::countRows( 'blog_text' ) - parent::countRows( 'blog' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'blog_entries', 'class' => 'IPS\blog\Entry' ), 2, array( 'app', 'link', 'class' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'blog_comments', 'class' => 'IPS\blog\Entry\Comment' ), 2, array( 'app', 'link', 'class' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'blog_entries', 'class' => 'IPS\blog\Entry' ), 3, array( 'app', 'link', 'class' ) );
|
||||
|
||||
return array( "f_blog_entries_rebuilding", "f_entry_comments_rebuilding", "f_blogs_recounting", "f_entry_tags_cache" );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ( $value != 'database' AND !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert blogs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertBlogs()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'bloguserid' );
|
||||
|
||||
foreach( $this->fetch( 'blog_user', 'bloguserid' ) as $blog )
|
||||
{
|
||||
try
|
||||
{
|
||||
$member = $this->db->select( '*', 'user', array( "userid=?", $blog['bloguserid'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
/* User no longer exists, so skip */
|
||||
$libraryClass->setLastKeyValue( $blog['bloguserid'] );
|
||||
continue;
|
||||
}
|
||||
|
||||
$socialgroup = NULL;
|
||||
|
||||
/* If this is a private blog, then we need to convert it to use a social group for invited users */
|
||||
if ( $blog['options_member'] == 0 AND $blog['options_buddy'] > 0 )
|
||||
{
|
||||
/* Fetch users friends */
|
||||
$friends = array();
|
||||
foreach( $this->db->select( 'relationid', 'userlist', array( "userid=?", $blog['bloguserid'] ) ) AS $friend )
|
||||
{
|
||||
$friends[$friend] = $friend;
|
||||
}
|
||||
|
||||
$socialgroup = array( 'members' => $friends );
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'blog_id' => $blog['bloguserid'],
|
||||
'blog_member_id' => $blog['bloguserid'],
|
||||
'blog_allowguests' => ( $blog['options_guest'] > 0 ) ? 1 : 0, # we don't care about specific options
|
||||
'blog_rating_total' => $blog['ratingtotal'],
|
||||
'blog_rating_count' => $blog['ratingnum'],
|
||||
'blog_settings' => array( 'allowrss' => TRUE ),
|
||||
'blog_name' => $blog['title'] ?: $member['username'] . "'s Blog",
|
||||
'blog_description' => $blog['description'] ?: '',
|
||||
'blog_last_edate' => $blog['lastblog'],
|
||||
'blog_count_entries' => $blog['entries'],
|
||||
'blog_count_comments' => $blog['comments'],
|
||||
'blog_count_entries_hidden' => $blog['deleted'],
|
||||
'blog_rating_average' => $blog['rating'],
|
||||
'blog_count_entries_future' => $blog['pending'],
|
||||
);
|
||||
|
||||
$libraryClass->convertBlog( $info, $socialgroup );
|
||||
|
||||
foreach( $this->db->select( '*', 'blog_subscribeuser', array( "userid=?", $blog['bloguserid'] ) ) AS $follow )
|
||||
{
|
||||
$frequency = 'none';
|
||||
if ( $follow['type'] == 'email' )
|
||||
{
|
||||
$frequency = 'immediate';
|
||||
}
|
||||
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'blog',
|
||||
'follow_area' => 'blogs',
|
||||
'follow_rel_id' => $blog['bloguserid'],
|
||||
'follow_rel_id_type' => 'blog_blogs',
|
||||
'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( $blog['bloguserid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert blog entries
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertBlogEntries()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'blogid' );
|
||||
|
||||
foreach( $this->fetch( 'blog', 'blogid' ) AS $entry )
|
||||
{
|
||||
try
|
||||
{
|
||||
$text = $this->db->select( '*', 'blog_text', array( "blogtextid=?", $entry['firstblogtextid'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$libraryClass->setLastKeyValue( $entry['blogid'] );
|
||||
continue;
|
||||
}
|
||||
|
||||
$lastcommenterid = 0;
|
||||
|
||||
try
|
||||
{
|
||||
$lastcommenterid = $this->db->select( 'userid', 'blog_text', array( "blogtextid=?", $entry['lastblogtextid'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
|
||||
$status = 'published';
|
||||
if ( $entry['state'] == 'draft' )
|
||||
{
|
||||
$status = 'draft';
|
||||
}
|
||||
|
||||
$edittime = $editname = NULL;
|
||||
try
|
||||
{
|
||||
$editlog = $this->db->select( 'dateline, username', 'blog_editlog', array( "blogtextid=?", $entry['firstblogtextid'] ), "dateline DESC" )->first();
|
||||
$edittime = $editlog['dateline'];
|
||||
$editname = $editlog['username'];
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
|
||||
$info = array(
|
||||
'entry_id' => $entry['blogid'],
|
||||
'entry_blog_id' => $entry['userid'],
|
||||
'entry_name' => $text['title'],
|
||||
'entry_content' => $text['pagetext'],
|
||||
'entry_author_id' => $entry['postedby_userid'],
|
||||
'entry_author_name' => $entry['postedby_username'],
|
||||
'entry_date' => $entry['dateline'],
|
||||
'entry_status' => $status,
|
||||
'entry_num_comments' => $entry['comments_visible'],
|
||||
'entry_queued_comments' => $entry['comments_moderation'],
|
||||
'entry_views' => $entry['views'],
|
||||
'entry_hidden_comments' => $entry['comments_deleted'],
|
||||
'entry_last_comment_mid' => $lastcommenterid,
|
||||
'entry_edit_time' => $edittime,
|
||||
'entry_edit_name' => $editname,
|
||||
'entry_ip_address' => $text['ipaddress']
|
||||
);
|
||||
|
||||
$libraryClass->convertBlogEntry( $info );
|
||||
|
||||
foreach( $this->db->select( '*', 'blog_rate', array( "blogid=?", $entry['blogid'] ) ) as $rating )
|
||||
{
|
||||
$libraryClass->convertRating( array(
|
||||
'id' => $rating['blograteid'],
|
||||
'class' => 'IPS\blog\Entry',
|
||||
'item_link' => 'blog_entries',
|
||||
'item_id' => $entry['blogid'],
|
||||
'rating' => $rating['vote'],
|
||||
'ip' => $rating['ipaddress'],
|
||||
'member' => $rating['userid'],
|
||||
) );
|
||||
}
|
||||
|
||||
$categories = explode( ',', $entry['categories'] );
|
||||
if ( count( $categories ) )
|
||||
{
|
||||
foreach( $categories as $category )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = $this->db->select( '*', 'blog_category', array( "blogcategoryid=?", $category ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$libraryClass->convertTag( array(
|
||||
'tag_meta_app' => 'blog',
|
||||
'tag_meta_area' => 'blogs',
|
||||
'tag_meta_parent_id' => $entry['userid'],
|
||||
'tag_meta_id' => $entry['blogid'],
|
||||
'tag_text' => $data['title'],
|
||||
'tag_member_id' => $data['userid'],
|
||||
'tag_prefix' => 0
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
foreach( $this->db->select( '*', 'blog_subscribeentry', array( "blogid=?", $entry['blogid'] ) ) AS $follow )
|
||||
{
|
||||
$frequency = 'none';
|
||||
if ( $follow['type'] == 'email' )
|
||||
{
|
||||
$frequency = 'immediate';
|
||||
}
|
||||
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'blog',
|
||||
'follow_area' => 'entries',
|
||||
'follow_rel_id' => $entry['blogid'],
|
||||
'follow_rel_id_type' => 'blog_entries',
|
||||
'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( $entry['blogid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert blog comments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertBlogComments()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'blogtextid' );
|
||||
|
||||
foreach( $this->fetch( 'blog_text', 'blogtextid' ) AS $comment )
|
||||
{
|
||||
/* Is this actually the entry? */
|
||||
try
|
||||
{
|
||||
$entry = $this->db->select( '*', 'blog', array( "firstblogtextid=?", $comment['blogtextid'] ) )->first();
|
||||
|
||||
/* If that didn't throw an exception, then yes this is - skip */
|
||||
$libraryClass->setLastKeyValue( $comment['blogtextid'] );
|
||||
continue;
|
||||
}
|
||||
catch( \UnderflowException $e ) {} # nope, carry on
|
||||
|
||||
$edittime = $editname = NULL;
|
||||
try
|
||||
{
|
||||
$editlog = $this->db->select( 'dateline, username', 'blog_editlog', array( "blogtextid=?", $comment['blogtextid'] ), "dateline DESC" )->first();
|
||||
$edittime = $editlog['dateline'];
|
||||
$editname = $editlog['username'];
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
|
||||
switch( $comment['state'] )
|
||||
{
|
||||
case 'moderation':
|
||||
$approved = 0;
|
||||
break;
|
||||
|
||||
case 'deleted':
|
||||
$approved = -1;
|
||||
break;
|
||||
|
||||
case 'visible':
|
||||
default:
|
||||
$approved = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
$libraryClass->convertBlogComment( array(
|
||||
'comment_id' => $comment['blogtextid'],
|
||||
'comment_entry_id' => $comment['blogid'],
|
||||
'comment_text' => $comment['pagetext'],
|
||||
'comment_member_id' => $comment['userid'],
|
||||
'comment_member_name' => $comment['username'],
|
||||
'comment_ip_address' => $comment['ipaddress'],
|
||||
'comment_date' => $comment['dateline'],
|
||||
'comment_edit_time' => $edittime,
|
||||
'comment_edit_member_name' => $editname,
|
||||
'comment_edit_show' => 1,
|
||||
'comment_approved' => $approved
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $comment['blogtextid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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::$entryContentType );
|
||||
$column = 'contentid';
|
||||
$table = 'attachment';
|
||||
}
|
||||
else
|
||||
{
|
||||
$column = 'blogid';
|
||||
$table = 'blog_attachment';
|
||||
}
|
||||
|
||||
foreach( $this->fetch( $table, 'attachmentid', $where ) as $attachment )
|
||||
{
|
||||
if ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) )
|
||||
{
|
||||
$filedata = $this->db->select( '*', 'filedata', array( "filedataid=?", $attachment['filedataid'] ) )->first();
|
||||
}
|
||||
else
|
||||
{
|
||||
$filedata = $attachment;
|
||||
$filedata['filedataid'] = $attachment['attachmentid'];
|
||||
}
|
||||
|
||||
$map = array(
|
||||
'id1' => $attachment[$column],
|
||||
'id2' => NULL
|
||||
);
|
||||
|
||||
$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 . '/' . $attachment['filedataid'] . '.attach';
|
||||
}
|
||||
|
||||
$attach_id = $libraryClass->convertAttachment( $info, $map, $path, $data );
|
||||
|
||||
/* Do some re-jiggery on the post itself to make sure attachment displays */
|
||||
$ourAttachment = \IPS\File::get( 'core_Attachment', \IPS\Db::i()->select( 'attach_location', 'core_attachments', array( 'attach_id=?', $attach_id ) )->first() );
|
||||
|
||||
$entry_id = $this->app->getLink( $attachment[ $column ], 'blog_entries' );
|
||||
|
||||
$post = \IPS\Db::i()->select( 'entry_content', 'blog_entries', array( "entry_id=?", $entry_id ) )->first();
|
||||
|
||||
if ( preg_match( "/\[ATTACH(.+?)?\]".$attachment['attachmentid']."\[\/ATTACH\]/i", $post ) )
|
||||
{
|
||||
$post = preg_replace( "/\[ATTACH=(.+?)?\]" . $attachment['attachmentid'] . "\[\/ATTACH\]/i", '<p><a href="<fileStore.core_Attachment>/' . (string) $ourAttachment . '" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="' . $attach_id . '" 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="' . $attach_id . '" src="<fileStore.core_Attachment>/' . (string) $ourAttachment . '" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>';
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'blog_entries', array( 'entry_content' => $post ), array( "entry_id=?", $entry_id ) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $attachment['attachmentid'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
<?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\Calendar;
|
||||
|
||||
/* 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(
|
||||
'convertCalendarCalendars' => array(
|
||||
'table' => 'calendars',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertCalendarEvents' => array(
|
||||
'table' => 'events',
|
||||
'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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'calendar_events', 'class' => 'IPS\calendar\Event' ), 2, array( 'app', 'link', 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\calendar\Event' ), 3, array( 'class' ) );
|
||||
|
||||
return array( "f_rebuild_events", "f_recount_calendar" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert calendars
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCalendarCalendars()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'cid' );
|
||||
|
||||
foreach( $this->fetch( 'calendars', 'cid' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertCalendar( array(
|
||||
'cal_id' => $row['cid'],
|
||||
'cal_title' => $row['name'],
|
||||
'cal_position' => $row['disporder'],
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['cid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert events
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCalendarEvents()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'eid' );
|
||||
|
||||
foreach( $this->fetch( 'events', 'eid' ) AS $row )
|
||||
{
|
||||
$repeats = \unserialize( $row['repeats'] );
|
||||
$recurring = NULL;
|
||||
|
||||
switch( $repeats['repeats'] )
|
||||
{
|
||||
case 1: # daily
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'daily',
|
||||
'event_repeat_freq' => $repeats['days'],
|
||||
);
|
||||
break;
|
||||
|
||||
case 2: # Monday through Friday
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'daily',
|
||||
'event_repeat_freq' => 1,
|
||||
'repeat_freq_on_MO' => 1,
|
||||
'repeat_freq_on_TU' => 1,
|
||||
'repeat_freq_on_WE' => 1,
|
||||
'repeat_freq_on_TH' => 1,
|
||||
'repeat_freq_on_FR' => 1
|
||||
);
|
||||
break;
|
||||
|
||||
case 3: # weekly
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'weekly',
|
||||
'event_repeat_freq' => $repeats['weeks'],
|
||||
'repeat_freq_on_SU' => isset( $repeats['days'][0] ) ? 1 : 0,
|
||||
'repeat_freq_on_MO' => isset( $repeats['days'][1] ) ? 1 : 0,
|
||||
'repeat_freq_on_TU' => isset( $repeats['days'][2] ) ? 1 : 0,
|
||||
'repeat_freq_on_WE' => isset( $repeats['days'][3] ) ? 1 : 0,
|
||||
'repeat_freq_on_TH' => isset( $repeats['days'][4] ) ? 1 : 0,
|
||||
'repeat_freq_on_FR' => isset( $repeats['days'][5] ) ? 1 : 0,
|
||||
'repeat_freq_on_SA' => isset( $repeats['days'][6] ) ? 1 : 0,
|
||||
);
|
||||
break;
|
||||
|
||||
case 4: # monthly recurring, specific day (day 16 of every month)
|
||||
/* We don't support specific day recurrence. */
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'monthly',
|
||||
'event_repeat_freq' => $repeats['months'],
|
||||
);
|
||||
break;
|
||||
|
||||
case 6: # yearly, specific day (October 16th, every year)
|
||||
case 7: # yearly, specific day (Every third Friday of October)
|
||||
/* We don't support specific days, and vBulletin doesn't support yearly frequencies more than 1 */
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'yearly',
|
||||
'event_repeat_freq' => 1,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
$libraryClass->convertCalendarEvent( array(
|
||||
'event_id' => $row['eid'],
|
||||
'event_calendar_id' => $row['cid'],
|
||||
'event_member_id' => $row['uid'],
|
||||
'event_title' => $row['name'],
|
||||
'event_content' => $row['description'],
|
||||
'event_saved' => $row['dateline'],
|
||||
'event_start_date' => \IPS\calendar\Date::ts( $row['starttime'] ),
|
||||
'event_end_date' => \IPS\calendar\Date::ts( $row['endtime'] ),
|
||||
'event_approved' => $row['visible'],
|
||||
'event_recurring' => $recurring,
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['eid'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter vBulletin 4.x Calendar 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\Calendar;
|
||||
|
||||
/* 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
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "vBulletin Calendar (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(
|
||||
'convertCalendarCalendars'=> array(
|
||||
'table' => 'calendar',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertCalendarEvents' => array(
|
||||
'table' => 'event',
|
||||
'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( '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( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'calendar_events', 'class' => 'IPS\calendar\Event' ), 2, array( 'app', 'link', 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\calendar\Event' ), 3, array( 'class' ) );
|
||||
|
||||
return array( "f_rebuild_events", "f_recount_calendar" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix Post Data
|
||||
*
|
||||
* @param string Post
|
||||
* @return string Fixed Posts
|
||||
*/
|
||||
public static function fixPostData( $post )
|
||||
{
|
||||
return \IPS\convert\Software\Core\Vbulletin::fixPostData( $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert calendars
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCalendarCalendars()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'calendarid' );
|
||||
|
||||
foreach( $this->fetch( 'calendar', 'calendarid' ) AS $calendar )
|
||||
{
|
||||
$libraryClass->convertCalendar( array(
|
||||
'cal_id' => $calendar['calendarid'],
|
||||
'cal_title' => $calendar['title'],
|
||||
'cal_moderate' => $calendar['moderatenew'],
|
||||
'cal_position' => $calendar['displayorder']
|
||||
) );
|
||||
|
||||
$libraryClass->setLastkeyValue( $calendar['calendarid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert events
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCalendarEvents()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'eventid' );
|
||||
|
||||
foreach( $this->fetch( 'event', 'eventid' ) AS $event )
|
||||
{
|
||||
/* We need to properly work out recurring, if possible - vBulletin stores basic recurring information versus our ICS Rules */
|
||||
$recurring = NULL;
|
||||
if ( $event['recurring'] )
|
||||
{
|
||||
switch( $event['recurring'] )
|
||||
{
|
||||
case 1: # daily recurring
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'daily',
|
||||
'event_repeat_freq' => $event['recuroption']
|
||||
);
|
||||
break;
|
||||
|
||||
case 2: # weekday recurring
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'daily',
|
||||
'event_repeat_freq' => 1,
|
||||
'repeat_freq_on_MO' => 1,
|
||||
'repeat_freq_on_TU' => 1,
|
||||
'repeat_freq_on_WE' => 1,
|
||||
'repeat_freq_on_TH' => 1,
|
||||
'repeat_freq_on_FR' => 1
|
||||
);
|
||||
break;
|
||||
|
||||
case 3: # weekly recurring
|
||||
$option = explode( "|", $event['recuroption'] );
|
||||
|
||||
$daybits = array(
|
||||
'SU' => 1,
|
||||
'MO' => 2,
|
||||
'TU' => 4,
|
||||
'WE' => 8,
|
||||
'TH' => 16,
|
||||
'FR' => 32,
|
||||
'SA' => 64
|
||||
);
|
||||
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'weekly',
|
||||
'event_repeat_freq' => $option[0],
|
||||
'repeat_freq_on_SU' => ( $option[1] & $daybits['SU'] ) ? 1 : 0,
|
||||
'repeat_freq_on_MO' => ( $option[1] & $daybits['MO'] ) ? 1 : 0,
|
||||
'repeat_freq_on_TU' => ( $option[1] & $daybits['TU'] ) ? 1 : 0,
|
||||
'repeat_freq_on_WE' => ( $option[1] & $daybits['WE'] ) ? 1 : 0,
|
||||
'repeat_freq_on_TH' => ( $option[1] & $daybits['TH'] ) ? 1 : 0,
|
||||
'repeat_freq_on_FR' => ( $option[1] & $daybits['FR'] ) ? 1 : 0,
|
||||
'repeat_freq_on_SA' => ( $option[1] & $daybits['SA'] ) ? 1 : 0,
|
||||
);
|
||||
break;
|
||||
|
||||
case 4: # monthly recurring, specific day (day 16 of every month)
|
||||
/* We don't support specific day recurrence. */
|
||||
$option = explode( "|", $event['recuroption'] );
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'monthly',
|
||||
'event_repeat_freq' => $option[1],
|
||||
);
|
||||
break;
|
||||
|
||||
case 5: # monthly recurring, specific day (third Friday of every month)
|
||||
/* We don't support specific day recurrence. */
|
||||
$option = explode( "|", $event['recuroption'] );
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'monthly',
|
||||
'event_repeat_freq' => $option[2]
|
||||
);
|
||||
break;
|
||||
|
||||
case 6: # yearly, specific day (October 16th, every year)
|
||||
case 7: # yearly, specific day (Every third Friday of October)
|
||||
/* We don't support specific days, and vBulletin doesn't support yearly frequencies more than 1 */
|
||||
$recurring = array(
|
||||
'event_repeat' => 1,
|
||||
'event_repeats' => 'yearly',
|
||||
'event_repeat_freq' => 1,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'event_id' => $event['eventid'],
|
||||
'event_calendar_id' => $event['calendarid'],
|
||||
'event_member_id' => $event['userid'],
|
||||
'event_title' => $event['title'],
|
||||
'event_content' => $event['event'],
|
||||
'event_saved' => $event['dateline'],
|
||||
'event_start_date' => \IPS\calendar\Date::ts( $event['dateline_from'] ),
|
||||
'event_end_date' => \IPS\calendar\Date::ts( $event['dateline_to'] ),
|
||||
'event_approved' => $event['visible'],
|
||||
'event_recurring' => $recurring
|
||||
);
|
||||
|
||||
$libraryClass->convertCalendarEvent( $info );
|
||||
|
||||
$libraryClass->setLastKeyValue( $event['eventid'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter Joomla 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\Cms;
|
||||
|
||||
/* 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 _Joomla extends \IPS\convert\Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "Joomla";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "joomla";
|
||||
}
|
||||
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function canConvert()
|
||||
{
|
||||
return array(
|
||||
'convertCmsDatabases' => array(
|
||||
'table' => 'cms_database',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertCmsDatabaseCategories' => array(
|
||||
'table' => 'categories',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertCmsDatabaseRecords' => array(
|
||||
'table' => 'content',
|
||||
'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 'cms_database':
|
||||
return 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return parent::countRows( $table, $where, $recache );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we convert passwords from this software.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function loginEnabled()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires Parent?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function requiresParent()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Available Parents
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function parents()
|
||||
{
|
||||
return array( 'core' => array( 'joomla' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish - Adds everything it needs to the queues and clears data store
|
||||
*
|
||||
* @return array Messages to display
|
||||
*/
|
||||
public function finish()
|
||||
{
|
||||
$database = $this->app->getLink( 1, 'cms_databases' );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\cms\Categories' . $database, 'count' => 0 ), 5, array( 'class' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'cms_custom_database_' . $database, 'class' => 'IPS\cms\Records' . $database ), 2, array( 'app', 'link', 'class' ) );
|
||||
|
||||
return array( "f_recount_cms_categories" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create database to store data in
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabases()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass->convertCmsDatabase( array(
|
||||
'database_id' => 1,
|
||||
'database_name' => "Joomla Posts",
|
||||
'database_sln' => 'article',
|
||||
'database_pln' => 'articles',
|
||||
'database_scn' => 'Article',
|
||||
'database_pcn' => 'Articles',
|
||||
'database_ia' => 'an article',
|
||||
'database_tags_enabled' => 1,
|
||||
), array(
|
||||
array(
|
||||
'field_id' => 1,
|
||||
'field_name' => 'Title',
|
||||
'field_type' => 'Text',
|
||||
'field_key' => 'post_title',
|
||||
'field_required' => 1,
|
||||
'field_position' => 1,
|
||||
'field_display_listing' => 1,
|
||||
'field_is_title' => 1,
|
||||
),
|
||||
array(
|
||||
'field_id' => 2,
|
||||
'field_name' => 'Content',
|
||||
'field_type' => 'Editor',
|
||||
'field_key' => 'post_content',
|
||||
'field_required' => 1,
|
||||
'field_position' => 3,
|
||||
'field_is_content' => 1,
|
||||
)
|
||||
) );
|
||||
|
||||
/* Throw an exception here to tell the library that we're done with this step */
|
||||
throw new \IPS\convert\Software\Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert categories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseCategories()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id' );
|
||||
|
||||
foreach( $this->fetch( 'categories', 'id' ) as $row )
|
||||
{
|
||||
$info = array(
|
||||
'category_id' => $row['id'],
|
||||
'category_database_id' => 1,
|
||||
'category_name' => $row['title'],
|
||||
'category_furl_name' => $row['alias'],
|
||||
'category_desc' => $row['description'],
|
||||
'category_fields' => array( 'post_title', 'post_content' ),
|
||||
);
|
||||
|
||||
$libraryClass->convertCmsDatabaseCategory( $info );
|
||||
$libraryClass->setLastKeyValue( $row['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert articles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseRecords()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id' );
|
||||
|
||||
foreach( $this->fetch( 'content', 'id' ) as $row )
|
||||
{
|
||||
/* Set the basic details */
|
||||
$info = array(
|
||||
'record_id' => $row['id'],
|
||||
'record_database_id' => 1,
|
||||
'member_id' => $row['created_by'],
|
||||
'record_allow_comments' => 1,
|
||||
'record_saved' => strtotime( $row['created'] ),
|
||||
'record_publish_date' => strtotime( $row['created'] ),
|
||||
'category_id' => $row['catid'],
|
||||
'record_approved' => ( $row['state'] != 0 ? 1 : 0 ),
|
||||
'record_updated' => ( strtotime( $row['modified'] ) > 0 ) ? strtotime( $row['modified'] ) : strtotime( $row['created'] ),
|
||||
'record_edit_member_id' => $row['modified_by'],
|
||||
);
|
||||
|
||||
/* Joomla saves half of a post in introtext and half in fulltext */
|
||||
if( isset( $row['introtext'] ) AND $row['introtext'] )
|
||||
{
|
||||
$row['fulltext'] = $row['fulltext'] ? $row['introtext'] . '<br><br>' . $row['fulltext'] : $row['introtext'];
|
||||
}
|
||||
|
||||
/* And then the custom fields */
|
||||
$fields = array(
|
||||
1 => $row['title'],
|
||||
2 => $row['fulltext']
|
||||
);
|
||||
|
||||
$libraryClass->convertCmsDatabaseRecord( $info, $fields );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,473 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter vBulletin 4.x Pages 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\Cms;
|
||||
|
||||
/* 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
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "vBulletin CMS (4.x only)";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'convertCmsBlocks' => array(
|
||||
'table' => 'cms_widget',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertCmsPages' => array(
|
||||
'table' => 'page',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertCmsDatabases' => array(
|
||||
'table' => 'database',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertCmsDatabaseCategories' => array(
|
||||
'table' => 'cms_category',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertCmsDatabaseRecords' => array(
|
||||
'table' => 'cms_article',
|
||||
'where' => NULL,
|
||||
),
|
||||
);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 'cms_widget':
|
||||
$blocksWeCanConvert = array();
|
||||
foreach( $this->db->select( 'widgettypeid', 'cms_widgettype', array( \IPS\Db::i()->in( 'class', array( 'Rss', 'Static' ) ) ) ) AS $typeid )
|
||||
{
|
||||
$blocksWeCanConvert[] = $typeid;
|
||||
}
|
||||
return $this->db->select( 'COUNT(*)', 'cms_widget', array( $this->db->in( 'widgettypeid', $blocksWeCanConvert ) ) )->first();
|
||||
break;
|
||||
|
||||
case 'page':
|
||||
case 'database':
|
||||
return 1;
|
||||
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( 'vbulletin' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix Post Data
|
||||
*
|
||||
* @param string Post
|
||||
* @return string Fixed Posts
|
||||
*/
|
||||
public static function fixPostData( $post )
|
||||
{
|
||||
return \IPS\convert\Software\Core\Vbulletin::fixPostData( $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a block of text, or a language string, that explains what the admin must do to start this conversion
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPreConversionInformation()
|
||||
{
|
||||
return 'convert_vb_preconvert';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Setting Value - useful for global settings that need to be translated to group or member settings
|
||||
*
|
||||
* @param string $key The setting key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _setting( $key )
|
||||
{
|
||||
if ( isset( $this->settingsCache[$key] ) )
|
||||
{
|
||||
return $this->settingsCache[$key];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$setting = $this->db->select( 'value, defaultvalue', 'setting', array( "varname=?", $key ) )->first();
|
||||
|
||||
if ( $setting['value'] )
|
||||
{
|
||||
$this->settingsCache[$key] = $setting['value'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->settingsCache[$key] = $setting['defaultvalue'];
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
/* If we failed to find it, we probably will fail again on later attempts */
|
||||
$this->settingsCache[$key] = NULL;
|
||||
}
|
||||
|
||||
return $this->settingsCache[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS blocks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsBlocks()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'widgetid' );
|
||||
|
||||
/* We CAN bring over some blocks, like static widgets */
|
||||
$blocksWeCanConvert = array();
|
||||
$rssTypeId = NULL;
|
||||
foreach( $this->db->select( 'widgettypeid, class', 'cms_widgettype', array( \IPS\Db::i()->in( 'class', array( 'Rss', 'Static' ) ) ) ) AS $type )
|
||||
{
|
||||
if ( $type['class'] == 'Rss' )
|
||||
{
|
||||
$rssTypeId = $type['widgettypeid'];
|
||||
}
|
||||
$blocksWeCanConvert[] = $type['widgettypeid'];
|
||||
}
|
||||
|
||||
foreach( $this->fetch( 'cms_widget', 'widgetid', array( \IPS\Db::i()->in( 'widgettypeid', $blocksWeCanConvert ) ) ) AS $block )
|
||||
{
|
||||
$config = $this->db->select( 'name, value', 'cms_widgetconfig', array( "widgetid=?", $block['widgetid'] ) )->setKeyField( 'name' )->setValueField( 'value' )->first();
|
||||
|
||||
$info = array(
|
||||
'block_id' => $block['widgetid'],
|
||||
'block_name' => $block['title'],
|
||||
'block_description' => $block['description'],
|
||||
'block_plugin' => ( $block['widgettypeid'] == $rssTypeId ) ? 'Rss' : NULL,
|
||||
'block_plugin_config' => ( $block['widgettypeid'] == $rssTypeId ) ? array(
|
||||
'block_rss_import_title' => $block['title'],
|
||||
'block_rss_import_url' => $config['url'],
|
||||
'block_rss_import_number' => $config['max_items'],
|
||||
'block_rss_import_cache' => 30,
|
||||
'block_type' => 'plugin',
|
||||
'block_editor' => 'html',
|
||||
'block_plugin' => 'Rss',
|
||||
'block_plugin_app' => 'cms',
|
||||
'template_params' => '',
|
||||
'type' => 'plugin',
|
||||
'plugin_app' => 'cms',
|
||||
) : NULL,
|
||||
'block_content' => ( $block['widgettypeid'] != $rssTypeId ) ? $config['statichtml'] : NULL,
|
||||
);
|
||||
|
||||
$libraryClass->convertCmsBlock( $info );
|
||||
|
||||
$libraryClass->setLastKeyValue( $block['widgetid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a CMS page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsPages()
|
||||
{
|
||||
$this->getLibrary()->convertCmsPage( array(
|
||||
'page_id' => 1,
|
||||
'page_name' => 'vBulletin Articles',
|
||||
) );
|
||||
|
||||
throw new \IPS\convert\Software\Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabases()
|
||||
{
|
||||
$convertedForums = FALSE;
|
||||
try
|
||||
{
|
||||
$this->app->checkForSibling( 'forums' );
|
||||
|
||||
$convertedForums = TRUE;
|
||||
}
|
||||
catch( \OutOfRangeException $e ) {}
|
||||
$this->getLibrary()->convertCmsDatabase( array(
|
||||
'database_id' => 1,
|
||||
'database_name' => 'vBulletin Articles',
|
||||
'database_sln' => 'article',
|
||||
'database_pln' => 'articles',
|
||||
'database_scn' => 'Article',
|
||||
'database_pcn' => 'Articles',
|
||||
'database_ia' => 'an article',
|
||||
'database_record_count' => $this->db->select( 'COUNT(*)', 'cms_article' )->first(),
|
||||
'database_tags_enabled' => 1,
|
||||
'database_forum_record' => ( $convertedForums ) ? 1 : 0,
|
||||
'database_forum_comments' => ( $convertedForums ) ? 1 : 0,
|
||||
'database_forum_delete' => ( $convertedForums ) ? 1 : 0,
|
||||
'database_forum_prefix' => ( $convertedForums ) ? 'Article: ' : '',
|
||||
'database_forum_forum' => ( $convertedForums ) ? $this->_setting( 'vbcmsforumid' ) : 0,
|
||||
'database_page_id' => 1,
|
||||
), array(
|
||||
array(
|
||||
'field_id' => 1,
|
||||
'field_type' => 'Text',
|
||||
'field_name' => 'Title',
|
||||
'field_key' => 'article_title',
|
||||
'field_required' => 1,
|
||||
'field_user_editable' => 1,
|
||||
'field_position' => 1,
|
||||
'field_display_listing' => 1,
|
||||
'field_display_display' => 1,
|
||||
'field_is_title' => TRUE,
|
||||
),
|
||||
array(
|
||||
'field_id' => 2,
|
||||
'field_type' => 'Editor',
|
||||
'field_name' => 'Content',
|
||||
'field_key' => 'article_content',
|
||||
'field_required' => 1,
|
||||
'field_user_editable' => 1,
|
||||
'field_position' => 2,
|
||||
'field_display_listing' => 0,
|
||||
'field_display_display' => 1,
|
||||
'field_is_content' => TRUE
|
||||
)
|
||||
) );
|
||||
|
||||
throw new \IPS\convert\Software\Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS database categories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseCategories()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'categoryid' );
|
||||
|
||||
foreach( $this->fetch( 'cms_category', 'categoryid' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertCmsDatabaseCategory( array(
|
||||
'category_id' => $row['categoryid'],
|
||||
'category_database_id' => 1,
|
||||
'category_name' => $row['category'],
|
||||
'category_desc' => $row['description'],
|
||||
'category_position' => $row['catleft'],
|
||||
'category_fields' => array( 'article_title', 'article_content' )
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['categoryid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS database records
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseRecords()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'contentid' );
|
||||
|
||||
foreach( $this->fetch( 'cms_article', 'contentid' ) AS $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
$node = $this->db->select( '*', 'cms_node', array( "contenttypeid=? AND contentid=?", $this->_articleContentType(), $row['contentid'] ) )->first();
|
||||
$nodeinfo = $this->db->select( '*', 'cms_nodeinfo', array( "nodeid=?", $node['nodeid'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$libraryClass->setLastKeyValue( $row['contentid'] );
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$category = $this->db->select( 'categoryid', 'cms_nodecategory', array( "nodeid=?", $node['nodeid'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
/* Create one */
|
||||
try
|
||||
{
|
||||
$this->app->getLink( '__orphan__', 'cms_database_categories' );
|
||||
|
||||
$category = '__orphan__';
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$libraryClass->convertCmsDatabaseCategory( array(
|
||||
'category_id' => '__orphan__',
|
||||
'category_database_id' => 1,
|
||||
'category_name' => "vBulletin Articles",
|
||||
'category_fields' => array( 'article_title', 'article_content' )
|
||||
) );
|
||||
|
||||
$category = '__orphan__';
|
||||
}
|
||||
}
|
||||
|
||||
$keywords = array();
|
||||
foreach( explode( ',', $nodeinfo['keywords'] ) AS $word )
|
||||
{
|
||||
$keywords[] = trim( $word );
|
||||
}
|
||||
|
||||
$libraryClass->convertCmsDatabaseRecord( array(
|
||||
'record_id' => $row['contentid'],
|
||||
'record_database_id' => 1,
|
||||
'member_id' => $node['userid'],
|
||||
'rating_real' => $nodeinfo['ratingtotal'],
|
||||
'rating_hits' => $nodeinfo['ratingnum'],
|
||||
'rating_value' => $nodeinfo['rating'],
|
||||
'record_locked' => $node['comments_enabled'],
|
||||
'record_views' => $nodeinfo['viewcount'],
|
||||
'record_allow_comments' => $node['comments_enabled'],
|
||||
'record_saved' => $node['publishdate'],
|
||||
'record_updated' => $node['lastupdated'],
|
||||
'category_id' => $category,
|
||||
'record_approved' => ( $node['hidden'] ) ? -1 : 1,
|
||||
'record_static_furl' => $node['url'],
|
||||
'record_meta_keywords' => $keywords,
|
||||
'record_meta_description' => $nodeinfo['description'],
|
||||
'record_topicid' => $nodeinfo['associatedthreadid'],
|
||||
'record_publish_date' => $node['publishdate'],
|
||||
), array(
|
||||
1 => $nodeinfo['title'],
|
||||
2 => $row['pagetext']
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['contentid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish - Adds everything it needs to the queues and clears data store
|
||||
*
|
||||
* @return array Messages to display
|
||||
*/
|
||||
public function finish()
|
||||
{
|
||||
foreach( \IPS\Db::i()->select( 'ipb_id', 'convert_link', array( 'type=? AND app=?', 'cms_databases', $this->app->app_id ) ) as $database )
|
||||
{
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\cms\Categories' . $database, 'count' => 0 ), 5, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\cms\Records'. $database ), 3, array( 'class' ) );
|
||||
|
||||
// This converter doesn't support tags at this time, uncomment when it does.
|
||||
//\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'cms_custom_database_' . $database, 'class' => 'IPS\cms\Records' . $database ), 3, array( 'app', 'link', 'class' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'cms_custom_database_' . $database, 'class' => 'IPS\cms\Records' . $database ), 2, array( 'app', 'link', 'class' ) );
|
||||
}
|
||||
|
||||
return array( "f_recount_cms_categories", "f_rebuild_cms_tags" );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cached article content type
|
||||
*/
|
||||
protected $_articleContentType = NULL;
|
||||
|
||||
/**
|
||||
* Return the article content type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _articleContentType()
|
||||
{
|
||||
if ( $this->_articleContentType === NULL )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->_articleContentType = $this->db->select( 'contenttypeid', 'contenttype', array( "class=?", 'Article' ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$this->_articleContentType = 24; # default
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_articleContentType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,489 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter Wordpress 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\Cms;
|
||||
|
||||
/* 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 _Wordpress extends \IPS\convert\Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "Wordpress (4.x)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "wordpress";
|
||||
}
|
||||
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function canConvert()
|
||||
{
|
||||
return array(
|
||||
'convertCmsPages' => array(
|
||||
'table' => 'posts',
|
||||
'where' => array( "post_type=?", 'page' )
|
||||
),
|
||||
'convertCmsDatabases' => array(
|
||||
'table' => 'cms_database',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertCmsDatabaseCategories' => array(
|
||||
'table' => 'term_taxonomy',
|
||||
'where' => array( "taxonomy=?", 'category' )
|
||||
),
|
||||
'convertCmsDatabaseRecords' => array(
|
||||
'table' => 'posts',
|
||||
'where' => array( "post_type=?", 'post' ),
|
||||
),
|
||||
'convertCmsDatabaseComments' => array(
|
||||
'table' => 'comments',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertCmsMedia' => array(
|
||||
'table' => 'posts',
|
||||
'where' => array( "post_type=?", 'attachment' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 'cms_database':
|
||||
return 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return parent::countRows( $table, $where, $recache );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires Parent?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function requiresParent()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Available Parents
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function parents()
|
||||
{
|
||||
return array( 'core' => array( 'wordpress' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* List of conversion methods that require additional information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
{
|
||||
return array(
|
||||
'convertCmsMedia',
|
||||
'convertCmsDatabaseRecords'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertCmsDatabaseRecords':
|
||||
$return['convertCmsDatabaseRecords']['file_location'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Text',
|
||||
'field_required' => TRUE,
|
||||
'field_default' => NULL,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack( 'convert_wp_typical_path' ),
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
);
|
||||
break;
|
||||
|
||||
case 'convertCmsMedia':
|
||||
$return['convertCmsMedia']['file_location'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Text',
|
||||
'field_required' => TRUE,
|
||||
'field_default' => NULL,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack( 'convert_wp_typical_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()
|
||||
{
|
||||
$database = $this->app->getLink( 1, 'cms_databases' );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\cms\Categories' . $database, 'count' => 0 ), 5, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\cms\Records'. $database ), 3, array( 'class' ) );
|
||||
|
||||
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'cms_records', 'class' => 'IPS\cms\Records' . $database ), 3, array( 'app', 'link', 'class' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'cms_custom_database_' . $database, 'class' => 'IPS\cms\Records' . $database ), 2, array( 'app', 'link', 'class' ) );
|
||||
|
||||
return array( "f_recount_cms_categories", "f_rebuild_cms_tags" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS pages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsPages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'ID' );
|
||||
|
||||
foreach( $this->fetch( 'posts', 'ID', array( "post_type=?", 'page' ) ) AS $row )
|
||||
{
|
||||
$libraryClass->convertCmsPage( array(
|
||||
'page_id' => $row['ID'],
|
||||
'page_name' => $row['post_title'],
|
||||
'page_seo_name' => $row['post_name'],
|
||||
'page_content' => $row['post_content'],
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS databases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabases()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass->convertCmsDatabase( array(
|
||||
'database_id' => 1,
|
||||
'database_name' => "WordPress Posts",
|
||||
'database_sln' => 'post',
|
||||
'database_pln' => 'posts',
|
||||
'database_scn' => 'Post',
|
||||
'database_pcn' => 'Posts',
|
||||
'database_ia' => 'a post',
|
||||
'database_tags_enabled' => 1,
|
||||
), array(
|
||||
array(
|
||||
'field_id' => 1,
|
||||
'field_name' => 'Title',
|
||||
'field_type' => 'Text',
|
||||
'field_key' => 'post_title',
|
||||
'field_required' => 1,
|
||||
'field_position' => 1,
|
||||
'field_display_listing' => 1,
|
||||
'field_is_title' => 1,
|
||||
),
|
||||
array(
|
||||
'field_id' => 2,
|
||||
'field_name' => 'Content',
|
||||
'field_type' => 'Editor',
|
||||
'field_key' => 'post_content',
|
||||
'field_required' => 1,
|
||||
'field_position' => 3,
|
||||
'field_is_content' => 1,
|
||||
)
|
||||
) );
|
||||
|
||||
/* Throw an exception here to tell the library that we're done with this step */
|
||||
throw new \IPS\convert\Software\Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS database categories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseCategories()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'term_taxonomy.term_taxonomy_id' );
|
||||
|
||||
foreach( $this->fetch( 'term_taxonomy', 'term_taxonomy.term_taxonomy_id', array( "term_taxonomy.taxonomy=?", 'category' ) )->join( 'terms', 'terms.term_id = term_taxonomy.term_id' ) AS $row )
|
||||
{
|
||||
$info = array(
|
||||
'category_id' => $row['term_taxonomy_id'],
|
||||
'category_database_id' => 1,
|
||||
'category_name' => $row['name'],
|
||||
'category_furl_name' => $row['slug'],
|
||||
'category_fields' => array( 'post_title', 'post_content' ),
|
||||
);
|
||||
|
||||
$libraryClass->convertCmsDatabaseCategory( $info );
|
||||
$libraryClass->setLastKeyValue( $row['term_taxonomy_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS database records
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseRecords()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'ID' );
|
||||
|
||||
foreach( $this->fetch( 'posts', 'ID', array( "post_type=?", 'post' ) ) AS $row )
|
||||
{
|
||||
/* We only support one category per record - in this instance, fetch them all, pop off the last one, then convert the rest as tags later. */
|
||||
$categories = array();
|
||||
foreach( $this->db->select( '*', 'term_relationships', array( "term_relationships.object_id=? AND term_taxonomy.taxonomy=?", $row['ID'], 'category' ) )->join( 'term_taxonomy', 'term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id' ) AS $term )
|
||||
{
|
||||
$categories[] = $term['term_taxonomy_id'];
|
||||
}
|
||||
$category = array_pop( $categories );
|
||||
|
||||
/* Post Meta */
|
||||
$meta = array();
|
||||
foreach( $this->db->select( '*', 'postmeta', array( "post_id=?", $row['ID'] ) ) AS $m )
|
||||
{
|
||||
$meta[$m['meta_key']] = $m['meta_value'];
|
||||
}
|
||||
|
||||
/* Work out wacky approved status */
|
||||
switch( $row['post_status'] )
|
||||
{
|
||||
case 'publish':
|
||||
$approved = 1;
|
||||
break;
|
||||
|
||||
case 'auto-draft':
|
||||
case 'draft':
|
||||
$approved = 0;
|
||||
break;
|
||||
|
||||
case 'trash':
|
||||
case 'private':
|
||||
$approved = -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
$approved = 0; # play it on the safe side.
|
||||
break;
|
||||
}
|
||||
|
||||
/* Record Image */
|
||||
$image = NULL;
|
||||
if ( isset( $meta['_thumbnail_id'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$location = $this->db->select( 'meta_value', 'postmeta', array( "post_id=? AND meta_key=?", $meta['_thumbnail_id'], '_wp_attached_file' ) )->first();
|
||||
$image = rtrim( $this->app->_session['more_info']['convertCmsDatabaseRecords']['file_location'], '/' ) . '/' . $location;
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'record_id' => $row['ID'],
|
||||
'record_database_id' => 1,
|
||||
'member_id' => $row['post_author'],
|
||||
'record_locked' => ( $row['comment_status'] == 'closed' ) ? 1 : 0,
|
||||
'record_comments' => $row['comment_count'],
|
||||
'record_allow_comments' => 1,
|
||||
'record_saved' => new \IPS\DateTime( $row['post_date'] ),
|
||||
'record_updated' => new \IPS\DateTime( $row['post_modified'] ),
|
||||
'category_id' => $category,
|
||||
'record_approved' => $approved,
|
||||
'record_dynamic_furl' => $row['post_name'],
|
||||
'record_static_furl' => $row['post_name'],
|
||||
'record_publish_date' => new \IPS\DateTime( $row['post_date'] ),
|
||||
'record_image' => $image,
|
||||
);
|
||||
|
||||
$fields = array(
|
||||
1 => $row['post_title'],
|
||||
2 => $row['post_content']
|
||||
);
|
||||
|
||||
$libraryClass->convertCmsDatabaseRecord( $info, $fields );
|
||||
|
||||
/* Tags */
|
||||
$tags = array();
|
||||
|
||||
/* ... from categories */
|
||||
foreach( $this->db->select( 'term_id', 'term_taxonomy', array( $this->db->in( 'term_taxonomy_id', $categories ) ) ) AS $cat )
|
||||
{
|
||||
$text = $this->db->select( 'name', 'terms', array( "term_id=?", $cat ) )->first();
|
||||
$tags[] = $text;
|
||||
}
|
||||
|
||||
/* ... from actual tags */
|
||||
foreach( $this->db->select( '*', 'term_relationships', array( "term_relationships.object_id=? AND term_taxonomy.taxonomy=?", $row['ID'], 'post_tag' ) )->join( 'term_taxonomy', 'term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id' ) AS $term )
|
||||
{
|
||||
$text = $this->db->select( 'name', 'terms', array( "term_id=?", $term['term_id'] ) )->first();
|
||||
$tags[] = $text;
|
||||
}
|
||||
|
||||
/* Now convert them... we need the database ID. */
|
||||
$database = $this->app->getLink( 1, 'cms_databases' );
|
||||
foreach( $tags AS $tag )
|
||||
{
|
||||
$libraryClass->convertTag( array(
|
||||
'tag_meta_app' => 'cms',
|
||||
'tag_meta_area' => "records{$database}",
|
||||
'tag_meta_parent_id' => $category,
|
||||
'tag_meta_id' => $row['ID'],
|
||||
'tag_text' => $tag,
|
||||
'tag_member_id' => $row['post_author'],
|
||||
'tag_prefix' => 0,
|
||||
'tag_meta_link' => 'cms_custom_database_' . $database,
|
||||
'tag_meta_parent_link' => 'cms_database_categories',
|
||||
) );
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS database comments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseComments()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'comment_ID' );
|
||||
|
||||
foreach( $this->fetch( 'comments', 'comment_ID' ) AS $row )
|
||||
{
|
||||
switch( $row['comment_approved'] )
|
||||
{
|
||||
case 1:
|
||||
$approved = 1;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
$approved = 0;
|
||||
break;
|
||||
|
||||
case 'trash':
|
||||
case 'spam':
|
||||
$approved = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
$libraryClass->convertCmsDatabaseComment( array(
|
||||
'comment_id' => $row['comment_ID'],
|
||||
'comment_database_id' => 1,
|
||||
'comment_record_id' => $row['comment_post_ID'],
|
||||
'comment_date' => new \IPS\DateTime( $row['comment_date'] ),
|
||||
'comment_ip_address' => $row['comment_author_IP'],
|
||||
'comment_user' => $row['user_id'],
|
||||
'comment_author' => $row['comment_author'],
|
||||
'comment_approved' => $approved,
|
||||
'comment_post' => $row['comment_content'],
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['comment_ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS media
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsMedia()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'ID' );
|
||||
|
||||
foreach( $this->fetch( 'posts', 'ID', array( "post_type=?", 'attachment' ) ) AS $row )
|
||||
{
|
||||
$meta = array();
|
||||
foreach( $this->db->select( '*', 'postmeta', array( "post_id=?", $row['ID'] ) ) AS $m )
|
||||
{
|
||||
$meta[$m['meta_key']] = $m['meta_value'];
|
||||
}
|
||||
|
||||
$filename = explode( '/', $meta['_wp_attached_file'] );
|
||||
$filename = array_pop( $filename );
|
||||
|
||||
$path = rtrim( $this->app->_session['more_info']['convertCmsMedia']['file_location'], '/' );
|
||||
|
||||
$info = array(
|
||||
'media_id' => $row['ID'],
|
||||
'media_filename' => $filename,
|
||||
'media_added' => new \IPS\DateTime( $row['post_date'] ),
|
||||
);
|
||||
|
||||
$libraryClass->convertCmsMedia( $info, $path . '/' . $meta['_wp_attached_file'] );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['ID'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter XenForo Page Nodes 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\Cms;
|
||||
|
||||
/* 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
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "XenForo Page Nodes";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'convertCmsPages' => array(
|
||||
'table' => 'xf_page',
|
||||
'where' => NULL,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses Prefix
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function usesPrefix()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires Parent
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function requiresParent()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible Parent Conversions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function parents()
|
||||
{
|
||||
return array( 'core' => array( 'xenforo' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to fetch a xenforo phrase
|
||||
*
|
||||
* @param string $title Phrase string
|
||||
* @return string|null Phrase
|
||||
*/
|
||||
protected function getPhrase( $title )
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->db->select( 'phrase_text', 'xf_phrase', array( "title=?", $title ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsPages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'xf_page.node_id' );
|
||||
|
||||
foreach( $this->fetch( 'xf_page', 'xf_page.node_id' )->join( 'xf_node', 'xf_node.node_id = xf_page.node_id' ) AS $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
$template = $this->db->select( 'template', 'xf_template', array( "title=?", "_page_node.{$row['node_id']}" ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$template = '';
|
||||
}
|
||||
|
||||
$libraryClass->convertCmsPage( array(
|
||||
'page_id' => $row['node_id'],
|
||||
'page_name' => $row['title'],
|
||||
'page_seo_name' => $row['node_name'],
|
||||
'page_content' => $template,
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['node_id'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter XenForoRm 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\Cms;
|
||||
|
||||
/* 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 _Xenfororm extends \IPS\convert\Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "XenForo Resource Manager Articles";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "xenfororm";
|
||||
}
|
||||
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function canConvert()
|
||||
{
|
||||
return array(
|
||||
'convertCmsDatabases' => array(
|
||||
'table' => 'cms_databases',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertCmsDatabaseCategories' => array(
|
||||
'table' => 'xf_resource_category',
|
||||
'where' => array( "allow_fileless=?", 1 )
|
||||
),
|
||||
'convertCmsDatabaseRecords' => array(
|
||||
'table' => 'xf_resource',
|
||||
'where' => array( "is_fileless=?", 1 )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 'cms_databases':
|
||||
return 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return parent::countRows( $table, $where, $recache );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses Prefix
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function usesPrefix()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires Parent
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function requiresParent()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible Parent Conversions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function parents()
|
||||
{
|
||||
return array( 'core' => array( 'xenforo' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CMS databases
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabases()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass->convertCmsDatabase( array(
|
||||
'database_id' => 1,
|
||||
'database_name' => "Resources",
|
||||
'database_sln' => 'resource',
|
||||
'database_pln' => 'resources',
|
||||
'database_scn' => 'Resource',
|
||||
'database_pcn' => 'Resources',
|
||||
'database_ia' => 'a resource',
|
||||
), array(
|
||||
array(
|
||||
'field_id' => 1,
|
||||
'field_name' => 'Title',
|
||||
'field_type' => 'Text',
|
||||
'field_key' => 'resource_title',
|
||||
'field_required' => 1,
|
||||
'field_position' => 1,
|
||||
'field_display_listing' => 1,
|
||||
'field_is_title' => 1,
|
||||
),
|
||||
array(
|
||||
'field_id' => 2,
|
||||
'field_name' => 'Tag Line',
|
||||
'field_type' => 'Text',
|
||||
'field_key' => 'resource_tagline',
|
||||
'field_required' => 1,
|
||||
'field_position' => 2,
|
||||
),
|
||||
array(
|
||||
'field_id' => 3,
|
||||
'field_name' => 'Content',
|
||||
'field_type' => 'Editor',
|
||||
'field_key' => 'resource_content',
|
||||
'field_required' => 1,
|
||||
'field_position' => 3,
|
||||
'field_is_content' => 1,
|
||||
)
|
||||
) );
|
||||
|
||||
/* Throw an exception here to tell the library that we're done with this step */
|
||||
throw new \IPS\convert\Software\Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS database categories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseCategories()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'resource_category_id' );
|
||||
|
||||
foreach( $this->fetch( 'xf_resource_category', 'resource_category_id', array( 'allow_fileless=?', 1 ) ) AS $row )
|
||||
{
|
||||
$forumoverride = 0;
|
||||
$forumid = 0;
|
||||
if ( $row['thread_node_id'] )
|
||||
{
|
||||
$forumoverride = 1;
|
||||
$forumid = $row['thread_node_id'];
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'category_id' => $row['resource_category_id'],
|
||||
'category_database_id' => 1,
|
||||
'category_name' => $row['category_title'],
|
||||
'category_position' => $row['display_order'],
|
||||
'category_fields' => array( 'resource_title', 'resource_tagline', 'resource_content' ),
|
||||
);
|
||||
|
||||
$libraryClass->convertCmsDatabaseCategory( $info );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['resource_category_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CMS database records
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseRecords()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'resource_id' );
|
||||
|
||||
foreach( $this->fetch( 'xf_resource', 'resource_id', array( 'is_fileless=?', 1 ) ) AS $row )
|
||||
{
|
||||
$post = $this->db->select( 'message, post_date', 'xf_resource_update', array( "resource_id=?", $row['resource_id'] ), "post_date DESC" )->first();
|
||||
|
||||
switch( $row['resource_state'] )
|
||||
{
|
||||
case 'visible':
|
||||
$approved = 1;
|
||||
break;
|
||||
|
||||
case 'moderated':
|
||||
$approved = 0;
|
||||
break;
|
||||
|
||||
case 'deleted':
|
||||
$approved = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'record_id' => $row['resource_id'],
|
||||
'record_database_id' => 1,
|
||||
'member_id' => $row['user_id'],
|
||||
'record_saved' => $row['resource_date'],
|
||||
'record_updated' => $post['post_date'],
|
||||
'category_id' => $row['resource_category_id'],
|
||||
'record_approved' => $approved,
|
||||
'record_topicid' => $row['discussion_thread_id'],
|
||||
'record_publish_date' => $row['resource_date'],
|
||||
);
|
||||
|
||||
$fields = array( 1 => $row['title'], 2 => $row['tag_line'], 3 => $post['message'] );
|
||||
|
||||
$libraryClass->convertCmsDatabaseRecord( $info, $fields );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['resource_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish - Adds everything it needs to the queues and clears data store
|
||||
*
|
||||
* @return array Messages to display
|
||||
*/
|
||||
public function finish()
|
||||
{
|
||||
$database = $this->app->getLink( 1, 'cms_databases' );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\cms\Categories' . $database, 'count' => 0 ), 5, array( 'class' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildContent', array( 'app' => $this->app->app_id, 'link' => 'cms_custom_database_' . $database, 'class' => 'IPS\cms\Records' . $database ), 2, array( 'app', 'link', 'class' ) );
|
||||
|
||||
return array( "f_recount_cms_categories", "f_rebuild_cms_tags" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,722 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter ExpressionEngine Master 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 14 June 2016
|
||||
*/
|
||||
|
||||
namespace IPS\convert\Software\Core;
|
||||
|
||||
/* 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()
|
||||
{
|
||||
return "Expression Engine";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
return 'expressionengine';
|
||||
}
|
||||
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function canConvert()
|
||||
{
|
||||
return array(
|
||||
'convertProfileFields' => array(
|
||||
'table' => 'exp_member_fields',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertGroups' => array(
|
||||
'table' => 'exp_member_groups',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertMembers' => array(
|
||||
'table' => 'exp_members',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertAttachments' => array(
|
||||
'table' => 'exp_members',
|
||||
'where' => array( "sig_img_filename<>''" )
|
||||
),
|
||||
'convertPrivateMessages' => array(
|
||||
'table' => 'exp_message_data',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertPrivateMessageReplies' => array(
|
||||
'table' => 'exp_message_data',
|
||||
'where' => NULL,
|
||||
'extra_steps' => array( 'convertPmAttachments' )
|
||||
),
|
||||
'convertPmAttachments' => array(
|
||||
'table' => 'exp_message_attachments',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertRanks' => array(
|
||||
'table' => 'exp_forum_ranks',
|
||||
'where' => NULL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we convert passwords from this software.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function loginEnabled()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we convert settings?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function canConvertSettings()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of Conversion Methods that require more information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
{
|
||||
return array(
|
||||
'convertAttachments',
|
||||
'convertProfileFields',
|
||||
'convertGroups',
|
||||
'convertMembers',
|
||||
'convertPrivateMessages'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix post data
|
||||
*
|
||||
* @param string raw post data
|
||||
* @return string parsed post data
|
||||
*/
|
||||
public static function fixPostData( $post )
|
||||
{
|
||||
return nl2br( $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
|
||||
switch ( $method )
|
||||
{
|
||||
case 'convertAttachments':
|
||||
$return['convertAttachments'] = array(
|
||||
'signature_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_sig_attach_path'),
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 'convertProfileFields':
|
||||
$return['convertProfileFields'] = array();
|
||||
|
||||
$options = array();
|
||||
$options['none'] = \IPS\Member::loggedIn()->language()->addToStack( 'none' );
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_pfields_data' ), 'IPS\core\ProfileFields\Field' ) AS $field )
|
||||
{
|
||||
$options[$field->_id] = $field->_title;
|
||||
}
|
||||
|
||||
foreach( $this->db->select( '*', 'exp_member_fields' ) AS $field )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["map_pfield_{$field['m_field_id']}"] = $field['m_field_label'];
|
||||
\IPS\Member::loggedIn()->language()->words["map_pfield_{$field['m_field_id']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_pfield_desc' );
|
||||
|
||||
$return['convertProfileFields']["map_pfield_{$field['m_field_id']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array( 'options' => $options ),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'convertGroups':
|
||||
$return['convertGroups'] = array();
|
||||
|
||||
$options = array();
|
||||
$options['none'] = 'None';
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
|
||||
{
|
||||
$options[$group->g_id] = $group->name;
|
||||
}
|
||||
|
||||
foreach( $this->db->select( '*', 'exp_member_groups' ) AS $group )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['group_id']}"] = $group['group_title'];
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['group_id']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_group_desc' );
|
||||
|
||||
$return['convertGroups']["map_group_{$group['group_id']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array( 'options' => $options ),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'convertMembers':
|
||||
$return['convertMembers'] = array();
|
||||
|
||||
/* We can only retain one type of photo */
|
||||
$return['convertMembers']['photo_type'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Radio',
|
||||
'field_default' => 'avatars',
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array( 'options' => array( 'avatars' => \IPS\Member::loggedIn()->language()->addToStack( 'avatars' ), 'profile_photos' => \IPS\Member::loggedIn()->language()->addToStack( 'profile_photos' ) ) ),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
|
||||
/* Find out where the photos live */
|
||||
\IPS\Member::loggedIn()->language()->words['photo_location_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'photo_location_nodb_desc' );
|
||||
$return['convertMembers']['photo_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_avatar_path'),
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
);
|
||||
|
||||
foreach( array( 'url', 'location', 'occupation', 'bio' ) AS $field )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field', FALSE, array( 'sprintf' => $field ) );
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field_desc' );
|
||||
$return['convertMembers']["field_{$field}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Radio',
|
||||
'field_default' => 'no_convert',
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(
|
||||
'options' => array(
|
||||
'no_convert' => \IPS\Member::loggedIn()->language()->addToStack( 'no_convert' ),
|
||||
'create_field' => \IPS\Member::loggedIn()->language()->addToStack( 'create_field' ),
|
||||
),
|
||||
'userSuppliedInput' => 'create_field'
|
||||
),
|
||||
'field_hint' => NULL
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'convertPrivateMessages':
|
||||
$return['convertPrivateMessages'] = array(
|
||||
'pm_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_pm_attach_path'),
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function finish()
|
||||
{
|
||||
/* Search Index Rebuild */
|
||||
\IPS\Content\Search\Index::i()->rebuild();
|
||||
|
||||
/* Clear Cache and Store */
|
||||
\IPS\Data\Store::i()->clearAll();
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
/* Non-Content Rebuilds */
|
||||
\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' ) );
|
||||
|
||||
/* Content Counts */
|
||||
\IPS\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' ) );
|
||||
|
||||
/* Attachments */
|
||||
\IPS\Task::queue( 'core', 'RebuildAttachmentThumbnails', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
|
||||
|
||||
return array( "f_search_index_rebuild", "f_clear_caches", "f_rebuild_pms", "f_signatures_rebuild", "f_rebuild_attachments" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert attachments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertAttachments()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'member_id' );
|
||||
|
||||
$it = $this->fetch( 'exp_members', 'member_id', array( "sig_img_filename<>''" ) );
|
||||
|
||||
foreach( $it AS $row )
|
||||
{
|
||||
$map = array(
|
||||
'id1' => $row['member_id'],
|
||||
'id1_type' => 'core_members',
|
||||
'id1_from_parent' => FALSE,
|
||||
'location_key' => 'core_Signatures'
|
||||
);
|
||||
|
||||
$ext = explode( '.', $row['sig_img_filename'] );
|
||||
$ext = array_pop( $ext );
|
||||
|
||||
$info = array(
|
||||
'attach_id' => $row['member_id'],
|
||||
'attach_file' => $row['sig_img_filename'],
|
||||
'attach_member_id' => $row['member_id'],
|
||||
'attach_ext' => $ext
|
||||
);
|
||||
|
||||
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['signature_attach_location'], '/' ) . '/' . $row['sig_img_filename'];
|
||||
|
||||
$attachId = $libraryClass->convertAttachment( $info, $map, $path );
|
||||
|
||||
/* Update Post if we can */
|
||||
try
|
||||
{
|
||||
if ( $attachId !== FALSE )
|
||||
{
|
||||
$ourAttachment = \IPS\File::get( 'core_Signature', \IPS\Db::i()->select( 'attach_location', 'core_attachments', array( 'attach_id=?', $attachId ) )->first() );
|
||||
|
||||
$memberId = $this->app->getLink( $row['member_id'], 'core_members' );
|
||||
|
||||
$signature = \IPS\Db::i()->select( 'signature', 'core_members', array( "member_id=?", $memberId ) )->first();
|
||||
|
||||
$signature .= '<p><a href="<fileStore.core_Signature>/' . (string) $ourAttachment . '" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="' . $attachId . '" src="<fileStore.core_Signature>/' . (string) $ourAttachment . '" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>';
|
||||
|
||||
\IPS\Db::i()->update( 'core_members', array( 'signature' => $signature ), array( "member_id=?", $memberId ) );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
catch( \OutOfRangeException $e ) {}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['member_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert profile fields
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertProfileFields()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
foreach( $this->fetch( 'exp_member_fields', 'm_field_id' ) AS $row )
|
||||
{
|
||||
$info = array();
|
||||
$info['pf_id'] = $row['m_field_id'];
|
||||
$merge = $this->app->_session['more_info']['convertProfileFields']["map_pfield_{$row['m_field_id']}"] != 'none' ? $this->app->_session['more_info']['convertProfileFields']["map_pfield_{$row['m_field_id']}"] : NULL;
|
||||
$info['pf_type'] = ucwords( $row['m_field_type'] );
|
||||
$info['pf_name'] = $row['m_field_label'];
|
||||
$info['pf_desc'] = $row['m_field_description'];
|
||||
$info['pf_content'] = ( !in_array( $row['m_field_type'], array( 'textbox', 'textarea' ) ) ) ? explode( "\r", $row['field_choices'] ) : NULL;
|
||||
$info['pf_not_null'] = $row['m_field_required'] == 'y' ? 1 : 0;
|
||||
$info['pf_member_hide'] = $row['m_field_public'] == 'n' ? 1 : 0;
|
||||
$info['pf_max_input'] = $row['m_field_maxl'];
|
||||
$info['pf_member_edit'] = ( in_array( $row['user_editable'], array( 'yes', 'once' ) ) ) ? 0 : 1;
|
||||
$info['pf_position'] = $row['m_field_order'];
|
||||
$info['pf_show_on_reg'] = $row['m_field_reg'] == 'y' ? 1 : 0;
|
||||
$info['pf_input_format'] = NULL;
|
||||
$info['pf_multiple'] = 0;
|
||||
|
||||
$libraryClass->convertProfileField( $info, $merge );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert groups
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGroups()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'group_id' );
|
||||
|
||||
foreach( $this->fetch( 'exp_member_groups', 'group_id' ) AS $row )
|
||||
{
|
||||
/* Basic info */
|
||||
$info = array(
|
||||
'g_id' => $row['group_id'],
|
||||
'g_name' => $row['group_title'],
|
||||
'g_view_board' => ( $row['can_view_online_system'] == 'y' ) ? 1 : 0,
|
||||
'g_use_pm' => ( $row['can_send_private_messages'] == 'y' ) ? 1 : 0,
|
||||
'g_max_messages' => $row['prv_msg_storage_limit'],
|
||||
'g_pm_perday' => $row['prv_msg_send_limit'],
|
||||
'g_search_flood' => $row['search_flood_control']
|
||||
);
|
||||
|
||||
$merge = ( $this->app->_session['more_info']['convertGroups']["map_group_{$row['group_id']}"] != 'none' ) ? $this->app->_session['more_info']['convertGroups']["map_group_{$row['group_id']}"] : NULL;
|
||||
|
||||
$libraryClass->convertGroup( $info, $merge );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['group_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert members
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertMembers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'exp_members.member_id' );
|
||||
|
||||
$it = $this->fetch( 'exp_members', 'exp_members.member_id' );
|
||||
|
||||
foreach( $it AS $row )
|
||||
{
|
||||
/* Main Member Information */
|
||||
$info = array(
|
||||
'member_id' => $row['member_id'],
|
||||
'name' => $row['screen_name'],
|
||||
'email' => $row['email'],
|
||||
'conv_password' => $row['password'],
|
||||
'member_group_id' => $row['group_id'],
|
||||
'joined' => $row['join_date'],
|
||||
'ip_address' => $row['ip_address'],
|
||||
'bday_day' => $row['bday_d'],
|
||||
'bday_month' => $row['bday_m'],
|
||||
'bday_year' => $row['bday_y'],
|
||||
'msg_count_total' => $row['private_messages'],
|
||||
'last_visit' => $row['last_visit'],
|
||||
'last_activity' => $row['last_activity'],
|
||||
'signature' => $row['signature'],
|
||||
'members_bitoptions' => array(
|
||||
'view_sigs' => ( $row['display_signatures'] == 'y' ) ? 1 : 0
|
||||
),
|
||||
'pp_setting_count_comments' => 1,
|
||||
'allow_admin_mails' => ( $row['accept_admin_email'] == 'y' ) ? 1 : 0,
|
||||
'member_posts' => $row['total_forum_posts'],
|
||||
);
|
||||
|
||||
/* Profile Fields */
|
||||
try
|
||||
{
|
||||
$profileFields = $this->db->select( '*', 'exp_member_data', array( "member_id=?", $row['member_id'] ) )->first();
|
||||
|
||||
unset( $profileFields['member_id'] );
|
||||
|
||||
/* Basic fields - we only need ID => Value, the library will handle the rest */
|
||||
foreach( $profileFields AS $key => $value )
|
||||
{
|
||||
$profileFields[ str_replace( 'm_field_id_', '', $key ) ] = $value;
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$profileFields = array();
|
||||
}
|
||||
|
||||
/* Pseudo Fields */
|
||||
foreach( array( 'url', 'location', 'occupation', 'bio' ) AS $pseudo )
|
||||
{
|
||||
/* Are we retaining? */
|
||||
if ( $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"] == 'no_convert' )
|
||||
{
|
||||
/* No, skip */
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
/* We don't actually need this, but we need to make sure the field was created */
|
||||
$fieldId = $this->app->getLink( $pseudo, 'core_pfields_data' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$libraryClass->convertProfileField( array(
|
||||
'pf_id' => $pseudo,
|
||||
'pf_name' => $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"],
|
||||
'pf_desc' => '',
|
||||
'pf_type' => 'Text',
|
||||
'pf_content' => '[]',
|
||||
'pf_member_hide' => 0,
|
||||
'pf_max_input' => 500,
|
||||
'pf_member_edit' => 1,
|
||||
'pf_show_on_reg' => 0,
|
||||
'pf_admin_only' => 0,
|
||||
) );
|
||||
}
|
||||
|
||||
$profileFields[ $pseudo ] = $row[ $pseudo ];
|
||||
}
|
||||
|
||||
/* Profile Photos */
|
||||
if ( $this->app->_session['more_info']['convertMembers']['photo_type'] == 'profile_photos' )
|
||||
{
|
||||
$filename = $row['photo_filename'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$filename = $row['avatar_filename'];
|
||||
}
|
||||
|
||||
$libraryClass->convertMember( $info, $profileFields, $filename, rtrim( $this->app->_session['more_info']['convertMembers']['photo_location'], '/' ) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['member_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ranks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertRanks()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'rank_id' );
|
||||
|
||||
foreach( $this->fetch( 'exp_forum_ranks', 'rank_id' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertRank( array(
|
||||
'id' => $row['rank_id'],
|
||||
'title' => $row['rank_title'],
|
||||
'posts' => $row['rank_min_posts'],
|
||||
'pips' => $row['rank_stars']
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['rank_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PMs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'message_id' );
|
||||
|
||||
foreach( $this->fetch( 'exp_message_data', 'message_id' ) AS $row )
|
||||
{
|
||||
/* Reset map array */
|
||||
$maps = array();
|
||||
|
||||
$topic = array(
|
||||
'mt_id' => $row['message_id'],
|
||||
'mt_date' => $row['message_date'],
|
||||
'mt_title' => $row['message_subject'],
|
||||
'mt_starter_id' => $row['sender_id'],
|
||||
'mt_start_time' => $row['message_date'],
|
||||
'mt_last_post_time' => $row['message_date'],
|
||||
'mt_to_count' => $row['total_recipients'],
|
||||
);
|
||||
|
||||
/* Author Map */
|
||||
$maps[ $row['sender_id'] ] = array(
|
||||
'map_user_id' => $row['sender_id'],
|
||||
'map_read_time' => $row['message_date'],
|
||||
'map_user_active' => 1,
|
||||
'map_user_banned' => 0,
|
||||
'map_has_unread' => 0,
|
||||
'map_is_starter' => 1,
|
||||
'map_last_topic_reply' => $row['message_date']
|
||||
);
|
||||
|
||||
foreach( $this->db->select( '*', 'exp_message_copies', array( 'message_id=?', $row['message_id'] ) ) AS $map )
|
||||
{
|
||||
$maps[ $map['recipient_id'] ] = array(
|
||||
'map_user_id' => $map['recipient_id'],
|
||||
'map_read_time' => $map['message_time_read'],
|
||||
'map_user_active' => 1,
|
||||
'map_user_banned' => 0,
|
||||
'map_has_unread' => ( $map['message_read'] == 'n' ) ? 1 : 0,
|
||||
'map_is_starter' => ( $map['recipient_id'] == $row['sender_id'] ) ? 1 : 0,
|
||||
'map_last_topic_reply' => $row['message_date']
|
||||
);
|
||||
}
|
||||
|
||||
$libraryClass->convertPrivateMessage( $topic, $maps );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['message_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PM replies
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessageReplies()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'message_id' );
|
||||
|
||||
foreach( $this->fetch( 'exp_message_data', 'message_id' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertPrivateMessageReply( array(
|
||||
'msg_id' => $row['message_id'],
|
||||
'msg_topic_id' => $row['message_id'],
|
||||
'msg_date' => $row['message_date'],
|
||||
'msg_post' => $row['message_body'],
|
||||
'msg_author_id' => $row['sender_id'],
|
||||
'msg_is_first_post' => 1,
|
||||
'msg_ip_address' => '127.0.0.1',
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['message_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PM attachments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPmAttachments()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'attachment_id' );
|
||||
|
||||
$it = $this->fetch( 'exp_message_attachments', 'attachment_id' );
|
||||
|
||||
foreach( $it AS $row )
|
||||
{
|
||||
$map = array(
|
||||
'id1' => $row['message_id'],
|
||||
'id1_type' => 'core_message_topics',
|
||||
'id1_from_parent' => FALSE,
|
||||
'id2' => $row['message_id'],
|
||||
'id2_type' => 'core_message_posts',
|
||||
'id2_from_parent' => FALSE
|
||||
);
|
||||
|
||||
$info = array(
|
||||
'attach_id' => $row['attachment_id'],
|
||||
'attach_file' => $row['attachment_name'],
|
||||
'attach_date' => $row['attachment_date'],
|
||||
'attach_member_id' => $row['sender_id'],
|
||||
'attach_ext' => \strtolower( trim( $row['attachment_extension'], '.' ) ),
|
||||
'attach_filesize' => ( $row['attachment_size'] * 1000 ), //convert to kb
|
||||
);
|
||||
|
||||
$path = rtrim( $this->app->_session['more_info']['convertAttachments']['pm_attach_location'], '/' ) . '/' . $row['attachment_hash'] . $row['attachment_extension'];
|
||||
|
||||
$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() );
|
||||
|
||||
$pmId = $this->app->getLink( $row['message_id'], 'core_message_posts' );
|
||||
|
||||
$message = \IPS\Db::i()->select( 'msg_post', 'core_message_posts', array( "msg_id=?", $pmId ) )->first();
|
||||
|
||||
$message .= '<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( 'core_message_posts', array( 'msg_post' => $message ), array( "msg_id=?", $pmId ) );
|
||||
}
|
||||
}
|
||||
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()
|
||||
{
|
||||
/* If we can't access profiles, don't bother trying to redirect */
|
||||
if( !\IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members' ) ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$url = \IPS\Request::i()->url();
|
||||
|
||||
if( preg_match( '#/member/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = (string) $this->app->getLink( (int) $matches[1], array( 'members', 'core_members' ) );
|
||||
return \IPS\Member::load( $data )->url();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter Joomla 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\Core;
|
||||
|
||||
/* 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 _Joomla extends \IPS\convert\Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "Joomla";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "joomla";
|
||||
}
|
||||
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function canConvert()
|
||||
{
|
||||
return array(
|
||||
'convertGroups' => array(
|
||||
'table' => 'usergroups',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertMembers' => array(
|
||||
'table' => 'users',
|
||||
'where' => NULL
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'convertGroups'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Method name
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertGroups':
|
||||
$return['convertGroups'] = array();
|
||||
|
||||
$options = array();
|
||||
$options['none'] = 'None';
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
|
||||
{
|
||||
$options[$group->g_id] = $group->name;
|
||||
}
|
||||
|
||||
foreach( $this->db->select( '*', 'usergroups' ) AS $group )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['id']}"] = $group['title'];
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['id']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_group_desc' );
|
||||
|
||||
$return['convertGroups']["map_group_{$group['id']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array( 'options' => $options ),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
}
|
||||
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()
|
||||
{
|
||||
/* Search Index Rebuild */
|
||||
\IPS\Content\Search\Index::i()->rebuild();
|
||||
|
||||
/* Clear Cache and Store */
|
||||
\IPS\Data\Store::i()->clearAll();
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
/* Content Counts */
|
||||
\IPS\Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
|
||||
|
||||
return array( "f_search_index_rebuild", "f_clear_caches" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert groups
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGroups()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id' );
|
||||
|
||||
foreach( $this->fetch( 'usergroups', 'id' ) as $row )
|
||||
{
|
||||
/* Basic info */
|
||||
$info = array(
|
||||
'g_id' => $row['id'],
|
||||
'g_name' => $row['title'],
|
||||
);
|
||||
|
||||
$merge = ( $this->app->_session['more_info']['convertGroups']["map_group_{$row['id']}"] != 'none' ) ? $this->app->_session['more_info']['convertGroups']["map_group_{$row['id']}"] : NULL;
|
||||
|
||||
$libraryClass->convertGroup( $info, $merge );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert members
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertMembers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id' );
|
||||
|
||||
foreach( $this->fetch( 'users', 'id' ) as $row )
|
||||
{
|
||||
/* Basic info */
|
||||
$info = array(
|
||||
'member_id' => $row['id'],
|
||||
'name' => $row['username'],
|
||||
'email' => $row['email'],
|
||||
'joined' => strtotime( $row['registerDate'] ),
|
||||
'mgroup_others' => array(),
|
||||
'temp_ban' => $row['block'] ? -1 : 0
|
||||
);
|
||||
|
||||
/* Figure out password */
|
||||
$pass = explode ( ':', $row['password'] );
|
||||
$info['conv_password'] = $pass[0];
|
||||
$info['conv_password_extra'] = $pass[1];
|
||||
|
||||
/* Figure out groups */
|
||||
$libraryClass::$usingKeys = FALSE;
|
||||
foreach( $this->fetch( 'user_usergroup_map', 'group_id', array( 'user_id=?', $row['id'] ), 'group_id' ) as $groupId )
|
||||
{
|
||||
/* First one we find we'll set as primary - Joomla does not make a distinction */
|
||||
if( !isset( $info['member_group_id'] ) )
|
||||
{
|
||||
$info['member_group_id'] = $groupId;
|
||||
}
|
||||
else
|
||||
{
|
||||
$info['mgroup_others'][] = $groupId;
|
||||
}
|
||||
}
|
||||
$libraryClass::$usingKeys = TRUE;
|
||||
|
||||
$libraryClass->convertMember( $info );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter Photopost Core 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\Core;
|
||||
|
||||
/* 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 _Photopost extends \IPS\convert\Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "Photopost";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "photopost";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
/* If we can't access profiles, don't bother trying to redirect */
|
||||
if( !\IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members' ) ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$url = \IPS\Request::i()->url();
|
||||
|
||||
if( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'member.php' ) !== FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = (string) $this->app->getLink( \IPS\Request::i()->cat, array( 'members', 'core_members' ) );
|
||||
return \IPS\Member::load( $data )->url();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter PhpMyForum Core 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\Core;
|
||||
|
||||
/* 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()
|
||||
{
|
||||
/* If we can't access profiles, don't bother trying to redirect */
|
||||
if( !\IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members' ) ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$url = \IPS\Request::i()->url();
|
||||
|
||||
if( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'profile.php' ) !== FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = (string) $this->app->getLink( \IPS\Request::i()->id, array( 'members', 'core_members' ) );
|
||||
return \IPS\Member::load( $data )->url();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
<?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\Core;
|
||||
|
||||
/* 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(
|
||||
'convertGroups' => array(
|
||||
'table' => 'groups',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertMembers' => array(
|
||||
'table' => 'users',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertRanks' => array(
|
||||
'table' => 'ranks',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertPrivateMessages' => array(
|
||||
'table' => 'messages',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertPrivateMessageReplies' => array(
|
||||
'table' => 'messages',
|
||||
'where' => NULL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'convertGroups',
|
||||
'convertMembers'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertGroups':
|
||||
$return['convertGroups'] = array();
|
||||
|
||||
$options = array();
|
||||
$options['none'] = 'None';
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
|
||||
{
|
||||
$options[$group->g_id] = $group->name;
|
||||
}
|
||||
|
||||
foreach( $this->db->select( '*', 'groups' ) AS $group )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['g_id']}"] = $group['g_title'];
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['g_id']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_group_desc' );
|
||||
|
||||
$return['convertGroups']["map_group_{$group['g_id']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array( 'options' => $options ),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'convertMembers':
|
||||
/* Pseudo Profile Fields */
|
||||
foreach( [ 'url', 'jabber', 'icq', 'msn', 'aim', 'yahoo', 'location' ] AS $field )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field', FALSE, array( 'sprintf' => ucwords( $field ) ) );
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field_desc' );
|
||||
$return['convertMembers']["field_{$field}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Radio',
|
||||
'field_default' => 'no_convert',
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(
|
||||
'options' => array(
|
||||
'no_convert' => \IPS\Member::loggedIn()->language()->addToStack( 'no_convert' ),
|
||||
'create_field' => \IPS\Member::loggedIn()->language()->addToStack( 'create_field' ),
|
||||
),
|
||||
'userSuppliedInput' => 'create_field'
|
||||
),
|
||||
'field_hint' => NULL
|
||||
);
|
||||
}
|
||||
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()
|
||||
{
|
||||
/* Search Index Rebuild */
|
||||
\IPS\Content\Search\Index::i()->rebuild();
|
||||
|
||||
/* Clear Cache and Store */
|
||||
\IPS\Data\Store::i()->clearAll();
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
/* Non-Content Rebuilds */
|
||||
\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' ) );
|
||||
|
||||
/* Content Counts */
|
||||
\IPS\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' ) );
|
||||
|
||||
return array( "f_search_index_rebuild", "f_clear_caches", "f_rebuild_pms", "f_signatures_rebuild" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix post data
|
||||
*
|
||||
* @param string raw post data
|
||||
* @return string parsed post data
|
||||
*/
|
||||
public static function fixPostData( $post )
|
||||
{
|
||||
$post = nl2br( $post );
|
||||
|
||||
$post = preg_replace( "#\[quote=(.+)\]#", "[quote name=$1]", $post );
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert groups
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGroups()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'g_id' );
|
||||
|
||||
foreach( $this->fetch( 'groups', 'g_id' ) AS $row )
|
||||
{
|
||||
$info = array(
|
||||
'g_id' => $row['g_id'],
|
||||
'g_name' => $row['g_title'],
|
||||
'g_view_board' => $row['g_read_board'],
|
||||
'g_mem_info' => $row['g_view_users'],
|
||||
'g_is_supmod' => $row['g_moderator'],
|
||||
'g_use_search' => $row['g_search'],
|
||||
'g_edit_posts' => $row['g_edit_posts'],
|
||||
'g_use_pm' => $row['g_pm'],
|
||||
'g_pm_flood_mins' => ( $row['g_email_flood'] ) ? ceil( $row['g_email_flood'] / 60 ) : 0,
|
||||
'g_delete_own_posts' => $row['g_delete_posts'],
|
||||
'g_avoid_flood' => ( $row['g_post_flood'] == 0 ) ? 1 : 0,
|
||||
'g_max_messages' => $row['g_pm_limit'],
|
||||
'prefix' => ( $row['g_color'] ) ? "<span style='color:{$row['g_color']}'>" : NULL,
|
||||
'suffix' => ( $row['g_color'] ) ? "</span>" : NULL,
|
||||
'g_search_flood' => $row['g_search_flood'],
|
||||
);
|
||||
|
||||
$merge = ( $this->app->_session['more_info']['convertGroups']["map_group_{$row['g_id']}"] != 'none' ) ? $this->app->_session['more_info']['convertGroups']["map_group_{$row['g_id']}"] : NULL;
|
||||
|
||||
$libraryClass->convertGroup( $info );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['g_id'], $merge );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert members
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertMembers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id' );
|
||||
|
||||
foreach( $this->fetch( 'users', 'id' ) AS $row )
|
||||
{
|
||||
$info = array(
|
||||
'member_id' => $row['id'],
|
||||
'email' => $row['email'],
|
||||
'name' => $row['username'],
|
||||
'password' => $row['password'],
|
||||
'conv_password_extra' => $row['salt'],
|
||||
'member_group_id' => $row['group_id'],
|
||||
'joined' => $row['registered'],
|
||||
'ip_address' => $row['registration_ip'],
|
||||
'last_visit' => $row['last_visit'],
|
||||
'last_activity' => $row['last_visit'],
|
||||
'auto_track' => ( $row['auto_notify'] ) ? [ 'content' => 1, 'comments' => 1, 'method' => 'immediate' ] : 0,
|
||||
'members_bitoptions' => [ 'view_sigs' => $row['show_sig'] ],
|
||||
'signature' => $row['signature'],
|
||||
'timezone' => $row['timezone'],
|
||||
'member_title' => $row['title'],
|
||||
'member_posts' => $row['num_posts'],
|
||||
);
|
||||
|
||||
/* Pseudo Fields */
|
||||
$profileFields = array();
|
||||
foreach( [ 'url', 'jabber', 'icq', 'msn', 'aim', 'yahoo', 'location' ] AS $pseudo )
|
||||
{
|
||||
/* Are we retaining? */
|
||||
if ( $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"] == 'no_convert' )
|
||||
{
|
||||
/* No, skip */
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
/* We don't actually need this, but we need to make sure the field was created */
|
||||
$fieldId = $this->app->getLink( $pseudo, 'core_pfields_data' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$libraryClass->convertProfileField( array(
|
||||
'pf_id' => $pseudo,
|
||||
'pf_name' => $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"],
|
||||
'pf_desc' => '',
|
||||
'pf_type' => 'Text',
|
||||
'pf_content' => '[]',
|
||||
'pf_member_hide' => 0,
|
||||
'pf_max_input' => 255,
|
||||
'pf_member_edit' => 1,
|
||||
'pf_show_on_reg' => 0,
|
||||
'pf_admin_only' => 0,
|
||||
) );
|
||||
}
|
||||
|
||||
$profileFields[$pseudo] = $row[$pseudo];
|
||||
}
|
||||
|
||||
$libraryClass->convertMember( $info, $profileFields );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ranks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertRanks()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id' );
|
||||
|
||||
foreach( $this->fetch( 'ranks', 'id' ) AS $row )
|
||||
{
|
||||
$info = array(
|
||||
'id' => $row['id'],
|
||||
'title' => $row['rank'],
|
||||
'posts' => $row['min_posts']
|
||||
);
|
||||
|
||||
$libraryClass->convertRank( $info );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert private messages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id' );
|
||||
|
||||
foreach( $this->fetch( 'messages', 'id' ) AS $row )
|
||||
{
|
||||
/* PunBB does not have conversations, so convert each one into and individual PM topic */
|
||||
$topic = array(
|
||||
'mt_id' => $row['id'],
|
||||
'mt_date' => $row['posted'],
|
||||
'mt_title' => $row['subject'],
|
||||
'mt_starter_id' => $row['sender_id'],
|
||||
'mt_start_time' => $row['posted'],
|
||||
'mt_last_post_time' => $row['posted'],
|
||||
'mt_to_count' => ( $row['sender_id'] == $row['owner'] ) ? 1 : 2,
|
||||
'mt_replies' => 1,
|
||||
);
|
||||
|
||||
$maps = array();
|
||||
|
||||
/* Sender */
|
||||
$maps[$row['sender_id']] = array(
|
||||
'map_user_id' => $row['sender_id'],
|
||||
'map_is_starter' => 1,
|
||||
'map_last_topic_reply' => $row['posted'],
|
||||
);
|
||||
|
||||
/* Recipient... if it isn't the sender */
|
||||
if ( $row['sender_id'] != $row['owner'] )
|
||||
{
|
||||
$maps[$row['owner']] = array(
|
||||
'map_user_id' => $row['owner'],
|
||||
'map_is_starter' => 0,
|
||||
'map_last_topic_reply' => $row['posted']
|
||||
);
|
||||
}
|
||||
|
||||
/* Simples! */
|
||||
$libraryClass->convertPrivateMessage( $topic, $maps );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PM replies
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessageReplies()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id' );
|
||||
|
||||
foreach( $this->fetch( 'messages', 'id' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertPrivateMessageReply( array(
|
||||
'msg_id' => $row['id'],
|
||||
'msg_topic_id' => $row['id'],
|
||||
'msg_date' => $row['posted'],
|
||||
'msg_post' => $row['message'],
|
||||
'msg_author_id' => $row['sender_id'],
|
||||
'msg_ip_address' => $row['sender_ip'],
|
||||
'msg_is_first_post' => 1,
|
||||
) );
|
||||
|
||||
$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()
|
||||
{
|
||||
/* If we can't access profiles, don't bother trying to redirect */
|
||||
if( !\IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members' ) ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$url = \IPS\Request::i()->url();
|
||||
|
||||
if( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'profile.php' ) !== FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = (string) $this->app->getLink( \IPS\Request::i()->u, array( 'members', 'core_members' ) );
|
||||
return \IPS\Member::load( $data )->url();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,894 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Converter Smf 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\Core;
|
||||
|
||||
/* 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(
|
||||
'convertBanfilters' => array(
|
||||
'table' => 'ban_items',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertEmoticons' => array(
|
||||
'table' => 'smileys',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertProfileFields' => array(
|
||||
'table' => 'custom_fields',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertGroups' => array(
|
||||
'table' => 'membergroups',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertMembers' => array(
|
||||
'table' => 'members',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertPrivateMessages' => array(
|
||||
'table' => 'personal_messages',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertPrivateMessageReplies' => array(
|
||||
'table' => 'personal_messages',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertIgnoredUsers' => array(
|
||||
'table' => 'members',
|
||||
'where' => array( 'LENGTH( pm_ignore_list ) > 0' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'convertEmoticons',
|
||||
'convertProfileFields',
|
||||
'convertGroups',
|
||||
'convertMembers'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 'ignored_users':
|
||||
try
|
||||
{
|
||||
return $this->db->select( 'SUM(CHAR_LENGTH(buddy_list) - CHAR_LENGTH(REPLACE(buddy_list, ",", "") + 1))', 'members', array( "pm_ignore_list!=?", '' ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return parent::countRows( $table, $where, $recache );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertEmoticons':
|
||||
$return['convertEmoticons']['emoticon_path'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Text',
|
||||
'field_default' => NULL,
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => NULL,
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
);
|
||||
$return['convertEmoticons']['keep_existing_emoticons'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Checkbox',
|
||||
'field_default' => TRUE,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
break;
|
||||
|
||||
case 'convertProfileFields':
|
||||
$return['convertProfileFields'] = array();
|
||||
|
||||
$options = array();
|
||||
$options['none'] = \IPS\Member::loggedIn()->language()->addToStack( 'none' );
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_pfields_data' ), 'IPS\core\ProfileFields\Field' ) AS $field )
|
||||
{
|
||||
$options[$field->_id] = $field->_title;
|
||||
}
|
||||
|
||||
foreach( $this->db->select( '*', 'custom_fields' ) AS $field )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["map_pfield_{$field['id_field']}"] = $field['field_name'];
|
||||
\IPS\Member::loggedIn()->language()->words["map_pfield_{$field['id_field']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_pfield_desc' );
|
||||
|
||||
$return['convertProfileFields']["map_pfield_{$field['id_field']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array( 'options' => $options ),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'convertGroups':
|
||||
$return['convertGroups'] = array();
|
||||
|
||||
$options = array();
|
||||
$options['none'] = \IPS\Member::loggedIn()->language()->addToStack( 'none' );
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
|
||||
{
|
||||
$options[$group->g_id] = $group->name;
|
||||
}
|
||||
|
||||
foreach( $this->db->select( '*', 'membergroups' ) AS $group )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['id_group']}"] = $group['group_name'];
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['id_group']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_group_desc' );
|
||||
|
||||
$return['convertGroups']["map_group_{$group['id_group']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array( 'options' => $options ),
|
||||
'field_hint' => NULL
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'convertMembers':
|
||||
$return['convertMembers'] = array();
|
||||
|
||||
$return['convertMembers']['username_or_display_name'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Radio',
|
||||
'field_default' => 'user_name',
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array( 'options' => array( 'user_name', 'display_name' ) ),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['photo_location_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'photo_location_nodb_desc' );
|
||||
$return['convertMembers']['photo_location'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Text',
|
||||
'field_default' => NULL,
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => "This is typically: /path/to/smf/attachments/",
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
);
|
||||
|
||||
$return['convertMembers']['gallery_location'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Text',
|
||||
'field_default' => NULL,
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => "This is typically: /path/to/smf/uploads/avatars/",
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
);
|
||||
|
||||
foreach( array( 'gender', 'website_url', 'location', 'icq', 'aim', 'yim', 'msn', 'personal_text' ) AS $field )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field', FALSE, array( 'sprintf' => $field ) );
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field_desc' );
|
||||
$return['convertMembers']["field_{$field}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Radio',
|
||||
'field_default' => 'no_convert',
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(
|
||||
'options' => array(
|
||||
'no_convert' => \IPS\Member::loggedIn()->language()->addToStack( 'no_convert' ),
|
||||
'create_field' => \IPS\Member::loggedIn()->language()->addToStack( 'create_field' ),
|
||||
),
|
||||
'userSuppliedInput' => 'create_field'
|
||||
),
|
||||
'field_hint' => NULL
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $return[ $method ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish - Adds everything it needs to the queues and clears data store
|
||||
*
|
||||
* @return array Message to display
|
||||
*/
|
||||
public function finish()
|
||||
{
|
||||
/* Search Index Rebuild */
|
||||
\IPS\Content\Search\Index::i()->rebuild();
|
||||
|
||||
/* Clear Cache and Store */
|
||||
\IPS\Data\Store::i()->clearAll();
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
/* Non-Content Rebuilds */
|
||||
\IPS\Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_members', 'extension' => 'core_Signatures' ), 2, array( 'app', 'link', 'extension' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_message_posts', 'extension' => 'core_Messaging' ), 2, array( 'app', 'link', 'extension' ) );
|
||||
|
||||
/* Content Counts */
|
||||
\IPS\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' ) );
|
||||
|
||||
/* Attachments */
|
||||
\IPS\Task::queue( 'core', 'RebuildAttachmentThumbnails', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
|
||||
|
||||
return array( "f_search_index_rebuild", "f_clear_caches", "f_rebuild_pms", "f_signatures_rebuild", "f_rebuild_attachments" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix post data
|
||||
*
|
||||
* @param string raw post data
|
||||
* @return string parsed post data
|
||||
*/
|
||||
public static function fixPostData( $post )
|
||||
{
|
||||
// Replace BBCode - The table HTML is removed by our parser, but it leaves the posts cleaner than having unparsed bbcode
|
||||
$search = array( '[li]', '[/li]', '[table]', '[/table]', '[tr]', '[/tr]', '[td]', '[/td]', '[tt]', '[/tt]' );
|
||||
$replace = array( '[*]', '', '<table>', '</table>', '<tr>', '</tr>', '<td>', '</td>', '[code]', '[/code]' );
|
||||
|
||||
$post = str_replace( $search, $replace, $post );
|
||||
|
||||
// And img tags
|
||||
$post = preg_replace("#\[img width=(\d+) height=(\d+)\]([a-zA-Z0-9.:\-/]+)\[\/img\]#i", "[img]$3[/img]", $post);
|
||||
|
||||
//Quotes
|
||||
$post = preg_replace("#\[quote author=(.+?) link=(.+?)=(\d+)\.msg(\d+)(.+?)date=(\d+)\](.+)\[\/quote\]#i", "[quote name=\"$1\" post=\"$4\" timestamp=\"$6\"]$7[/quote]", $post);
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ban filters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertBanfilters()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id_ban' );
|
||||
|
||||
foreach( $this->fetch( 'ban_items', 'id_ban' ) AS $row )
|
||||
{
|
||||
/* Hostnames aren't supported, and Members are done later */
|
||||
if ( $row['hostname'] OR $row['id_member'] )
|
||||
{
|
||||
$libraryClass->setLastKeyValue( $row['id_ban'] );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $row['ip_low1'] AND $row['ip_low2'] AND $row['ip_low3'] AND $row['ip_low4'] )
|
||||
{
|
||||
$libraryClass->convertBanfilter( array(
|
||||
'ban_id' => $row['id_ban'],
|
||||
'ban_type' => 'ip',
|
||||
'ban_content' => $row['ip_low1'] . '.' . $row['ip_low2'] . '.' . $row['ip_low3'] . '.' . $row['ip_low4']
|
||||
) );
|
||||
}
|
||||
|
||||
if ( $row['email_address'] )
|
||||
{
|
||||
$libraryClass->convertBanfilter( array(
|
||||
'ban_id' => $row['id_ban'],
|
||||
'ban_type' => 'email',
|
||||
'ban_content' => $row['email_address'],
|
||||
) );
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id_ban'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert emoticons
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertEmoticons()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id_smiley' );
|
||||
|
||||
foreach( $this->fetch( 'smileys', 'id_smiley' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertEmoticon( array(
|
||||
'id' => $row['id_smiley'],
|
||||
'typed' => $row['code'],
|
||||
'filename' => $row['filename'],
|
||||
'clickable' => !$row['hidden'],
|
||||
'emo_position' => $row['smiley_order']
|
||||
), array(
|
||||
'set' => md5( 'Converted' ),
|
||||
'title' => 'Converted',
|
||||
'position' => 1
|
||||
), $this->app->_session['more_info']['convertEmoticons']['keep_existing_emoticons'], rtrim( $this->app->_session['more_info']['convertEmoticons']['emoticon_path'], '/' ) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id_smiley'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert private messages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id_pm' );
|
||||
|
||||
foreach( $this->fetch( 'personal_messages', 'id_pm' ) AS $row )
|
||||
{
|
||||
$topic = array(
|
||||
'mt_id' => $row['id_pm'],
|
||||
'mt_date' => $row['msgtime'],
|
||||
'mt_title' => $row['subject'],
|
||||
'mt_starter_id' => $row['id_member_from'],
|
||||
'mt_start_time' => $row['msgtime'],
|
||||
'mt_last_post_time' => $row['msgtime'],
|
||||
'mt_to_count' => 0,
|
||||
'mt_replies' => 0,
|
||||
);
|
||||
|
||||
$maps = array(
|
||||
$row['id_member_from'] = array(
|
||||
'map_user_id' => $row['id_member_from'],
|
||||
'map_read_time' => time(),
|
||||
'map_user_active' => ( $row['deleted_by_sender'] ) ? 0 : 1,
|
||||
'map_user_banned' => 0,
|
||||
'map_has_unread' => 0,
|
||||
'map_is_starter' => 1,
|
||||
'map_last_topic_reply' => $row['msgtime']
|
||||
)
|
||||
);
|
||||
|
||||
foreach( $this->db->select( '*', 'pm_recipients', array( "id_pm=?", $row['id_pm'] ) ) AS $map )
|
||||
{
|
||||
if( !isset( $maps[ $map['id_member'] ] ) )
|
||||
{
|
||||
$maps[ $map['id_member'] ] = array(
|
||||
'map_user_id' => $map['id_member'],
|
||||
'map_read_time' => $map['is_new'] ? time() : 0,
|
||||
'map_user_active' => $map['deleted'] ? 0 : 1,
|
||||
'map_user_banned' => 0,
|
||||
'map_has_unread' => $map['is_new'],
|
||||
'map_is_starter' => 0,
|
||||
'map_last_topic_reply' => $row['msgtime']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$libraryClass->convertPrivateMessage( $topic, $maps );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id_pm'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PM replies
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessageReplies()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id_pm' );
|
||||
|
||||
foreach( $this->fetch( 'personal_messages', 'id_pm' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertPrivateMessageReply( array(
|
||||
'msg_id' => $row['id_pm'],
|
||||
'msg_topic_id' => $row['id_pm'],
|
||||
'msg_date' => $row['msgtime'],
|
||||
'msg_post' => $row['body'],
|
||||
'msg_author_id' => $row['id_member_from'],
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id_pm'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert custom fields
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertProfileFields()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id_field' );
|
||||
|
||||
foreach( $this->fetch( 'custom_fields', 'id_field' ) AS $row )
|
||||
{
|
||||
$type = NULL;
|
||||
switch( $row['field_type'] )
|
||||
{
|
||||
case 'textarea':
|
||||
$type = 'TextArea';
|
||||
break;
|
||||
|
||||
case 'check':
|
||||
$type = 'Checkbox';
|
||||
break;
|
||||
|
||||
default:
|
||||
$type = ucwords( $row['field_type'] );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $row['mask'] == 'email' )
|
||||
{
|
||||
$type = 'Email';
|
||||
}
|
||||
|
||||
if ( $row['mask'] == 'number' )
|
||||
{
|
||||
$type = 'Number';
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'pf_id' => $row['col_name'],
|
||||
'pf_type' => $type,
|
||||
'pf_name' => $row['field_name'],
|
||||
'pf_desc' => $row['field_desc'],
|
||||
'pf_content' => ( in_array( $row['field_type'], array( 'select', 'radio' ) ) ) ? json_encode( explode( ',', $row['field_options'] ) ) : NULL,
|
||||
'pf_not_null' => ( $row['show_reg'] == 2 ) ? 1 : 0,
|
||||
'pf_member_hide' => ( $row['private'] >= 3 ) ? 1 : 0,
|
||||
'pf_max_input' => ( !in_array( $row['field_type'], array( 'select', 'radio', 'check' ) ) ) ? $row['field_length'] : NULL,
|
||||
'pf_member_edit' => ( $row['private'] < 4 ) ? 1 : 0,
|
||||
'pf_position' => $row['placement'],
|
||||
'pf_show_on_reg' => ( $row['show_reg'] >= 1 ) ? 1 : 0,
|
||||
'pf_input_format' => ( mb_substr( $row['mask'], 0, 5 ) == 'regex' ) ? str_replace( 'regex', '', $row['mask'] ) : NULL,
|
||||
'pf_admin_only' => ( $row['private'] == 4 ) ? 1 : 0,
|
||||
);
|
||||
|
||||
$merge = ( $this->app->_session['more_info']['convertProfileFields']["map_pfield_{$row['id_field']}"] != 'none' ) ? $this->app->_session['more_info']['convertProfileFields']["map_pfield_{$row['id_field']}"] : NULL;
|
||||
|
||||
$libraryClass->convertProfileField( $info, $merge );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id_field'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert groups
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGroups()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id_group' );
|
||||
|
||||
foreach( $this->fetch( 'membergroups', 'id_group' ) AS $row )
|
||||
{
|
||||
$prefix = NULL;
|
||||
$suffix = NULL;
|
||||
|
||||
if ( $row['online_color'] )
|
||||
{
|
||||
$prefix = "<span style='color:{$row['online_color']}'>";
|
||||
$suffix = "</span>";
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'g_id' => $row['id_group'],
|
||||
'g_name' => $row['group_name'],
|
||||
'prefix' => $prefix,
|
||||
'suffix' => $suffix,
|
||||
'g_max_messages' => $row['max_messages'],
|
||||
);
|
||||
|
||||
$merge = $this->app->_session['more_info']['convertGroups']["map_group_{$row['id_group']}"] != 'none' ? $this->app->_session['more_info']['convertGroups']["map_group_{$row['id_group']}"] : NULL;
|
||||
|
||||
$libraryClass->convertGroup( $info, $merge );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id_group'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert members
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertMembers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id_member' );
|
||||
|
||||
foreach( $this->fetch( 'members', 'id_member' ) AS $row )
|
||||
{
|
||||
$name = $row['real_name'];
|
||||
|
||||
if ( $this->app->_session['more_info']['convertMembers']['username_or_display_name'] == 'username' )
|
||||
{
|
||||
$name = $row['member_name'];
|
||||
}
|
||||
|
||||
/* Restrictions */
|
||||
$ban = 0;
|
||||
$rp = 0;
|
||||
try
|
||||
{
|
||||
$ban_data = $this->db->select( '*', 'ban_groups', array( "id_ban_group=?", $this->db->select( 'id_ban_group', 'ban_items', array( "id_member=?", $row['id_member'] ) )->first() ) )->first();
|
||||
|
||||
$time = -1;
|
||||
if ( $ban_data['expire_time'] )
|
||||
{
|
||||
$time = $ban_data['expire_time'];
|
||||
}
|
||||
|
||||
if ( $ban_data['cannot_access'] )
|
||||
{
|
||||
$ban = $time;
|
||||
}
|
||||
|
||||
if ( $ban_data['cannot_post'] )
|
||||
{
|
||||
$rp = $time;
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
|
||||
$bday_year = $bday_month = $bday_day = NULL;
|
||||
|
||||
/* Make sure it isn't the SMF placeholder */
|
||||
if( $row['birthdate'] != '0001-01-01' )
|
||||
{
|
||||
list( $bday_year, $bday_month, $bday_day ) = explode( '-', $row['birthdate'] );
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'member_id' => $row['id_member'],
|
||||
'email' => $row['email_address'],
|
||||
'name' => $name,
|
||||
'password' => $row['passwd'],
|
||||
'password_extra' => $row['password_salt'],
|
||||
'member_group_id' => $row['id_group'],
|
||||
'joined' => $row['date_registered'],
|
||||
'ip_address' => $row['member_ip'],
|
||||
'msg_count_new' => $row['unread_messages'],
|
||||
'msg_count_total' => $row['instant_messages'],
|
||||
'msg_show_notification' => $row['new_pm'],
|
||||
'last_visit' => $row['last_login'],
|
||||
'last_activity' => $row['last_login'],
|
||||
'restrict_post' => $rp,
|
||||
'temp_ban' => $ban,
|
||||
'bday_day' => $bday_day,
|
||||
'bday_month' => $bday_month,
|
||||
'bday_year' => $bday_year,
|
||||
'mgroup_others' => $row['additional_groups'],
|
||||
'signature' => $row['signature'],
|
||||
'pp_reputation_points' => $row['karma_good'] - $row['karma_bad'],
|
||||
'timezone' => $row['time_offset'],
|
||||
'allow_admin_mails' => $row['notify_announcements'],
|
||||
'member_title' => $row['usertitle'],
|
||||
'member_posts' => $row['posts'],
|
||||
);
|
||||
|
||||
$pfields = array();
|
||||
|
||||
/* Pseudo Profile Fields */
|
||||
foreach( array( 'gender', 'website_url', 'location', 'icq', 'aim', 'yim', 'msn', 'personal_text' ) AS $pseudo )
|
||||
{
|
||||
/* Are we retaining? */
|
||||
if ( $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"] == 'no_convert' )
|
||||
{
|
||||
/* No, skip */
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$fieldId = $this->app->getLink( $pseudo, 'core_pfields_data' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$type = 'Text';
|
||||
$content = '[]';
|
||||
switch( $pseudo )
|
||||
{
|
||||
case 'gender':
|
||||
$type = 'Select';
|
||||
$content = json_encode( [ 'Male', 'Female', 'Undisclosed' ] );
|
||||
break;
|
||||
|
||||
case 'personal_text':
|
||||
$type = 'TextArea';
|
||||
break;
|
||||
}
|
||||
|
||||
$libraryClass->convertProfileField( array(
|
||||
'pf_id' => $pseudo,
|
||||
'pf_name' => $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"],
|
||||
'pf_desc' => '',
|
||||
'pf_type' => $type,
|
||||
'pf_content' => $content,
|
||||
'pf_member_hide' => 0,
|
||||
'pf_max_input' => 255,
|
||||
'pf_member_edit' => 1,
|
||||
'pf_show_on_reg' => 0,
|
||||
'pf_admin_only' => 0,
|
||||
) );
|
||||
}
|
||||
|
||||
switch( $pseudo )
|
||||
{
|
||||
case 'gender':
|
||||
switch( $row[$pseudo] )
|
||||
{
|
||||
case 1:
|
||||
$pfields[$pseudo] = 'Male';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$pfields[$pseudo] = 'Female';
|
||||
break;
|
||||
|
||||
default:
|
||||
$pfields[$pseudo] = 'Undisclosed';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$pfields[$pseudo] = $row[$pseudo];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Real Profile Fields */
|
||||
foreach( $this->db->select( 'variable, value', 'themes', array( "id_member=?", $row['id_member'] ) )->setKeyField( 'variable' )->setValueField( 'value' ) AS $key => $value )
|
||||
{
|
||||
$pfields[$key] = $value;
|
||||
}
|
||||
|
||||
/* Photos */
|
||||
$filedata = NULL;
|
||||
$filename = NULL;
|
||||
$filepath = NULL;
|
||||
if ( $row['avatar'] )
|
||||
{
|
||||
if ( mb_substr( $row['avatar'], 0, 4 ) == 'http' )
|
||||
{
|
||||
/* Remote */
|
||||
try
|
||||
{
|
||||
$file = \IPS\Http\Url::external( $row['avatar'] )->request()->get();
|
||||
|
||||
$filename = explode( '/', $row['avatar'] );
|
||||
$filename = array_pop( $filename );
|
||||
$filedata = (string) $file;
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Gallery */
|
||||
$file = rtrim( $this->app->_session['more_info']['convertMembers']['gallery_location'], '/' );
|
||||
if ( @file_exists( $file . '/' . $row['avatar'] ) )
|
||||
{
|
||||
$filename = $row['avatar'];
|
||||
$filepath = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Maybe Uploaded */
|
||||
try
|
||||
{
|
||||
$attach = $this->db->select( '*', 'attachments', array( "id_member=? AND filename LIKE CONCAT( ?, '%' )", $row['id_member'], 'avatar_' ) )->first();
|
||||
|
||||
$file = rtrim( $this->app->_session['more_info']['convertMembers']['photo_location'], '/' );
|
||||
|
||||
/* We need to figure out where it is */
|
||||
if ( $attach['file_hash'] )
|
||||
{
|
||||
$location = $attach['id_attach'] . '_' . $attach['file_hash'];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clean filename per legacy SMF requirements */
|
||||
$cleanName = strtr( $attach['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 = $attach['id_attach'] . '_' . str_replace( '.', '_', $cleanName ) . md5( $cleanName );
|
||||
}
|
||||
|
||||
if ( @file_exists( $file . '/' . $location ) )
|
||||
{
|
||||
$filename = $attach['filename'];
|
||||
$filedata = file_get_contents( $file . '/' . $location );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
}
|
||||
|
||||
$libraryClass->convertMember( $info, $pfields, $filename, $filepath, $filedata );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id_member'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ignored users
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertIgnoredUsers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'id_member' );
|
||||
|
||||
foreach( $this->fetch( 'members', 'id_member', array( 'LENGTH( pm_ignore_list ) > 0' ) ) AS $row )
|
||||
{
|
||||
if ( !$row['pm_ignore_list'] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach( explode( ',', $row['pm_ignore_list'] ) AS $id )
|
||||
{
|
||||
$info = array();
|
||||
$info['ignore_id'] = $row['id_member'] . '_' . $id;
|
||||
$info['ignore_owner_id'] = $row['id_member'];
|
||||
$info['ignore_ignore_id'] = $id;
|
||||
|
||||
foreach( \IPS\core\Ignore::types() AS $type )
|
||||
{
|
||||
$info['ignore_' . $type] = 1;
|
||||
}
|
||||
$libraryClass->convertIgnoredUser( $info );
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['id_member'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we can redirect the legacy URLs from this software to the new locations
|
||||
*
|
||||
* @return NULL|\IPS\Http\Url
|
||||
* @note Current profile URL format: /index.php?action=profile;u=123
|
||||
*/
|
||||
public function checkRedirects()
|
||||
{
|
||||
/* If we can't access profiles, don't bother trying to redirect */
|
||||
if( !\IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members' ) ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( isset( \IPS\Request::i()->action ) AND mb_strpos( \IPS\Request::i()->action, 'profile' ) !== FALSE )
|
||||
{
|
||||
if( isset( \IPS\Request::i()->u ) )
|
||||
{
|
||||
$oldId = \IPS\Request::i()->u;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pieces = explode( ';', \IPS\Request::i()->action );
|
||||
|
||||
foreach( $pieces as $piece )
|
||||
{
|
||||
$_pieces = explode( '=', $piece );
|
||||
|
||||
if( $_pieces[0] === 'u' )
|
||||
{
|
||||
$oldId = (int) $_pieces[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$data = (string) $this->app->getLink( $oldId, array( 'members', 'core_members' ) );
|
||||
return \IPS\Member::load( $data )->url();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,776 @@
|
||||
<?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\Core;
|
||||
|
||||
/* 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
|
||||
{
|
||||
/**
|
||||
* @brief Emoticons WHERE statement
|
||||
* @see convertEmoticons()
|
||||
*/
|
||||
protected static $emoticonsWhere = 'GRAEMLIN_IS_ACTIVE=1';
|
||||
|
||||
/**
|
||||
* @brief Groups WHERE statement
|
||||
* @see convertGroups()
|
||||
*/
|
||||
protected static $groupsWhere = 'GROUP_IS_DISABLED=0';
|
||||
|
||||
/**
|
||||
* @brief Ignored users WHERE statement
|
||||
* @see convertIgnoredUsers()
|
||||
*/
|
||||
protected static $ignoredUsersWhere = "USER_IGNORE_LIST IS NOT NULL AND USER_IGNORE_LIST NOT IN ( '', '-' )";
|
||||
|
||||
/**
|
||||
* @brief Members WHERE statement
|
||||
* @see convertMembers()
|
||||
*/
|
||||
protected static $membersWhere = array( 'u.USER_LOGIN_NAME<>?', '**DONOTDELETE**' );
|
||||
|
||||
/**
|
||||
* This is.. kind of hacky, but it's used so we can try and support non-exact profanity matches without converting
|
||||
* other regexes we don't support
|
||||
*
|
||||
* @brief Profanity filters WHERE statement
|
||||
* @see convertProfanityFilters()
|
||||
*/
|
||||
protected static $profanityFiltersWhere = '(
|
||||
CENSOR_WORD NOT LIKE "%(.*)%" AND (
|
||||
CENSOR_WORD NOT LIKE "%(.*?)%" OR (
|
||||
CENSOR_WORD LIKE "%(.*?)" AND CENSOR_WORD NOT LIKE "%(.*?)%(.*?)"
|
||||
)
|
||||
)
|
||||
)';
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'convertEmoticons' => array(
|
||||
'table' => 'GRAEMLINS',
|
||||
'where' => static::$emoticonsWhere,
|
||||
),
|
||||
'convertBanfilters' => array(
|
||||
'table' => 'pseudo_banfilters', /** @see countRows() */
|
||||
'where' => NULL
|
||||
),
|
||||
'convertGroups' => array(
|
||||
'table' => 'GROUPS',
|
||||
'where' => static::$groupsWhere
|
||||
),
|
||||
'convertMembers' => array(
|
||||
'table' => array( 'USERS', 'u' ),
|
||||
'where' => static::$membersWhere,
|
||||
'extra_steps' => array( 'convertMembersFollowers' ),
|
||||
),
|
||||
'convertIgnoredUsers' => array(
|
||||
'table' => 'USER_PROFILE',
|
||||
'where' => static::$ignoredUsersWhere
|
||||
),
|
||||
'convertMembersFollowers' => array(
|
||||
'table' => 'WATCH_LISTS',
|
||||
'where' => array( 'WATCH_TYPE=?', 'u' )
|
||||
),
|
||||
'convertRanks' => array(
|
||||
'table' => 'USER_TITLES',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertPrivateMessages' => array(
|
||||
'table' => 'PRIVATE_MESSAGE_TOPICS',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertPrivateMessageReplies' => array(
|
||||
'table' => 'PRIVATE_MESSAGE_POSTS',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertProfanityFilters' => array(
|
||||
'table' => 'CENSOR_LIST',
|
||||
'where' => static::$profanityFiltersWhere
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we convert passwords from this software.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function loginEnabled()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 'pseudo_banfilters':
|
||||
return parent::countRows( 'BANNED_EMAILS' )
|
||||
+ parent::countRows( 'BANNED_HOSTS' )
|
||||
+ parent::countRows( 'RESERVED_NAMES' );
|
||||
}
|
||||
|
||||
return parent::countRows( $table, $where, $recache );
|
||||
}
|
||||
|
||||
/**
|
||||
* List of conversion methods that require additional information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
{
|
||||
return array(
|
||||
'convertEmoticons',
|
||||
'convertGroups',
|
||||
'convertMembers'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to convert a textual date(time) representation to a DateTime instance
|
||||
*
|
||||
* @param string $date
|
||||
* @return \IPS\DateTime|null
|
||||
*/
|
||||
protected function stringToDateTime( $date )
|
||||
{
|
||||
try
|
||||
{
|
||||
return new \IPS\DateTime( $date );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertEmoticons':
|
||||
$return['convertEmoticons'] = array();
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['emoticon_path'] = \IPS\Member::loggedIn()->language()->addToStack( 'source_path', FALSE, array( 'sprintf' => array( 'UBBthreads' ) ) );
|
||||
$return['convertEmoticons']['emoticon_path'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Text',
|
||||
'field_default' => NULL,
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => NULL
|
||||
);
|
||||
$return['convertEmoticons']['keep_existing_emoticons'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Checkbox',
|
||||
'field_default' => TRUE,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
break;
|
||||
|
||||
case 'convertGroups':
|
||||
$return['convertGroups'] = array();
|
||||
|
||||
$options = array();
|
||||
$options['none'] = \IPS\Member::loggedIn()->language()->addToStack( 'none' );
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_groups' ), 'IPS\Member\Group' ) AS $group )
|
||||
{
|
||||
$options[ $group->g_id ] = $group->name;
|
||||
}
|
||||
|
||||
foreach( $this->db->select( '*', 'GROUPS' ) AS $group )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['GROUP_ID']}"] = $group['GROUP_NAME'];
|
||||
\IPS\Member::loggedIn()->language()->words["map_group_{$group['GROUP_ID']}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'map_group_desc' );
|
||||
|
||||
$return['convertGroups']["map_group_{$group['GROUP_ID']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array( 'options' => $options ),
|
||||
'field_hint' => NULL
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'convertMembers':
|
||||
$return['convertMembers'] = array();
|
||||
|
||||
/* Should we use the username or display name property when converting? */
|
||||
$return['convertMembers']['username'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Radio',
|
||||
'field_default' => 'display_name',
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array( 'options' => array( 'username' => \IPS\Member::loggedIn()->language()->addToStack( 'user_name' ), 'display_name' => \IPS\Member::loggedIn()->language()->addToStack( 'display_name' ) ) ),
|
||||
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack( 'username_hint' ),
|
||||
);
|
||||
|
||||
foreach( array( 'homepage', 'occupation', 'hobbies', 'location', 'icq', 'yahoo', 'aim', 'msn' ) AS $field )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field', FALSE, array( 'sprintf' => $field ) );
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field_desc' );
|
||||
$return['convertMembers']["field_{$field}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Radio',
|
||||
'field_default' => 'no_convert',
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(
|
||||
'options' => array(
|
||||
'no_convert' => \IPS\Member::loggedIn()->language()->addToStack( 'no_convert' ),
|
||||
'create_field' => \IPS\Member::loggedIn()->language()->addToStack( 'create_field' ),
|
||||
),
|
||||
'userSuppliedInput' => 'create_field'
|
||||
),
|
||||
'field_hint' => NULL
|
||||
);
|
||||
}
|
||||
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()
|
||||
{
|
||||
/* Search Index Rebuild */
|
||||
\IPS\Content\Search\Index::i()->rebuild();
|
||||
|
||||
/* Clear Cache and Store */
|
||||
\IPS\Data\Store::i()->clearAll();
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
/* Non-Content Rebuilds */
|
||||
\IPS\Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_members', 'extension' => 'core_Signatures' ), 2, array( 'app', 'link', 'extension' ) );
|
||||
\IPS\Task::queue( 'convert', 'RebuildNonContent', array( 'app' => $this->app->app_id, 'link' => 'core_message_posts', 'extension' => 'core_Messaging' ), 2, array( 'app', 'link', 'extension' ) );
|
||||
|
||||
/* Content Counts */
|
||||
\IPS\Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\core\Messenger\Conversation' ), 3, array( 'class' ) );
|
||||
|
||||
/* First Post Data */
|
||||
\IPS\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 ), 4, array( 'app' ) );
|
||||
|
||||
return array( "f_search_index_rebuild", "f_clear_caches", "f_rebuild_pms", "f_signatures_rebuild", "f_rebuild_attachments" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix post data
|
||||
*
|
||||
* @param string raw post data
|
||||
* @return string parsed post data
|
||||
*/
|
||||
public static function fixPostData( $post )
|
||||
{
|
||||
$post = preg_replace( "#\[quote=(.+?)\]#i", "[quote name=\"$1\"]", $post );
|
||||
$post = str_ireplace( [ "[image]", '[/image]', '[size:', '[color:' ], [ '[img]', '[/img]', '[size=', '[color=' ], $post );
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ban filters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertBanfilters()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
/* Banned e-mails */
|
||||
foreach ( $this->db->select( 'BANNED_EMAIL', 'BANNED_EMAILS' ) as $row )
|
||||
{
|
||||
$libraryClass->convertBanfilter( array(
|
||||
'ban_id' => $row, // We don't actually have an ID column
|
||||
'ban_type' => 'email',
|
||||
'ban_content' => str_replace( '%', '*', $row ) // Replace UBB's wildcard character
|
||||
) );
|
||||
}
|
||||
|
||||
/* Banned IP's */
|
||||
foreach( $this->db->select( 'BANNED_HOST', 'BANNED_HOSTS' ) as $row )
|
||||
{
|
||||
$libraryClass->convertBanfilter( array(
|
||||
'ban_id' => $row, // We don't actually have an ID column
|
||||
'ban_type' => 'ip',
|
||||
'ban_content' => str_replace( '%', '*', $row ) // Replace UBB's wildcard character
|
||||
) );
|
||||
}
|
||||
|
||||
/* Banned / "reserved" names */
|
||||
foreach ( $this->db->select( 'RESERVED_USERNAME', 'RESERVED_NAMES' ) as $row )
|
||||
{
|
||||
$libraryClass->convertBanfilter( array(
|
||||
'ban_id' => $row, // We don't actually have an ID column
|
||||
'ban_type' => 'name',
|
||||
'ban_content' => str_replace( '%', '*', $row ) // Replace UBB's wildcard character; TODO: Verify UBB actually supports wildcards here
|
||||
) );
|
||||
}
|
||||
|
||||
throw new \IPS\convert\Software\Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert emoticons
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertEmoticons()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
foreach( $this->fetch( 'GRAEMLINS', 'GRAEMLIN_ID', static::$emoticonsWhere ) as $row )
|
||||
{
|
||||
$info = array(
|
||||
'id' => $row['GRAEMLIN_ID'],
|
||||
'typed' => $row['GRAEMLIN_SMILEY_CODE'] ?: ':'.$row['GRAEMLIN_MARKUP_CODE'].':',
|
||||
'width' => $row['GRAEMLIN_WIDTH'],
|
||||
'height' => $row['GRAEMLIN_HEIGHT'],
|
||||
'filename' => $row['GRAEMLIN_IMAGE'],
|
||||
'emo_position' => $row['GRAEMLIN_ID'],
|
||||
);
|
||||
|
||||
$set = array(
|
||||
'set' => md5( 'Converted' ),
|
||||
'title' => 'Converted',
|
||||
'position' => 1,
|
||||
);
|
||||
|
||||
$libraryClass->convertEmoticon(
|
||||
$info, $set, $this->app->_session['more_info']['convertEmoticons']['keep_existing_emoticons'],
|
||||
rtrim( $this->app->_session['more_info']['convertEmoticons']['emoticon_path'], '/' ) . "/images/graemlins/default"
|
||||
);
|
||||
$libraryClass->setLastKeyValue( $row['GRAEMLIN_ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert groups
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGroups()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'GROUP_ID' );
|
||||
|
||||
foreach ( $this->fetch( 'GROUPS', 'GROUP_ID', static::$groupsWhere ) as $row )
|
||||
{
|
||||
/* @TODO: Can we enable custom titles per group? */
|
||||
$info = array(
|
||||
'g_id' => $row['GROUP_ID'],
|
||||
'g_name' => $row['GROUP_NAME'],
|
||||
);
|
||||
|
||||
$merge = $this->app->_session['more_info']['convertGroups']["map_group_{$row['GROUP_ID']}"] != 'none' ? $this->app->_session['more_info']['convertGroups']["map_group_{$row['GROUP_ID']}"] : NULL;
|
||||
|
||||
$libraryClass->convertGroup( $info, $merge );
|
||||
$libraryClass->setLastKeyValue( $row['GROUP_ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ignored users
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertIgnoredUsers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'USER_ID' );
|
||||
|
||||
foreach ( $this->fetch( 'USER_PROFILE', 'USER_ID', static::$ignoredUsersWhere ) as $row )
|
||||
{
|
||||
/* Proper database modeling? CSV's? JSON? What are those things? */
|
||||
foreach ( explode( '-', $row['USER_IGNORE_LIST'] ) as $ignoredMemberMaybe )
|
||||
{
|
||||
if ( ! $ignoredMemberMaybe )
|
||||
{
|
||||
/* We split an empty string. Fabulous. */
|
||||
continue;
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'ignore_id' => $row['USER_ID'] . '-' . $ignoredMemberMaybe,
|
||||
'ignore_owner_id' => $row['USER_ID'],
|
||||
'ignore_ignore_id' => $ignoredMemberMaybe
|
||||
);
|
||||
|
||||
/* Assume we want to ignore everything by this member */
|
||||
foreach ( \IPS\core\Ignore::types() as $type )
|
||||
{
|
||||
$info[ 'ignore_' . $type ] = 1;
|
||||
}
|
||||
|
||||
$libraryClass->convertIgnoredUser( $info );
|
||||
$libraryClass->setLastKeyValue( $row['USER_ID'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert members
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertMembers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'u.USER_ID' );
|
||||
|
||||
$select = $this->fetch( array( 'USERS', 'u' ), 'u.USER_ID', static::$membersWhere )
|
||||
->join( array( 'BANNED_USERS', 'b' ), 'u.USER_ID=b.USER_ID', 'LEFT' )
|
||||
->join( array( 'USER_PROFILE', 'p' ), 'u.USER_ID=p.USER_ID' )
|
||||
->join( array( 'USER_DATA', 'd' ), 'u.USER_ID=d.USER_ID' );
|
||||
|
||||
foreach ( $select as $row )
|
||||
{
|
||||
/* Birthday */
|
||||
$birthday = array( 'day' => NULL, 'month' => NULL, 'year' => NULL );
|
||||
|
||||
if ( $birthdayDt = $this->stringToDateTime( $row['USER_BIRTHDAY'] ) )
|
||||
{
|
||||
$birthday['day'] = $birthdayDt->format( 'j' );
|
||||
$birthday['month'] = $birthdayDt->format( 'n' );
|
||||
$birthday['year'] = $birthdayDt->format( 'Y' );
|
||||
}
|
||||
|
||||
/* Member groups */
|
||||
$secondaryGroups = iterator_to_array( $this->db->select( 'GROUP_ID', 'USER_GROUPS', array( 'USER_ID=?', $row['USER_ID'] ) ) );
|
||||
$primaryGroup = array_shift( $secondaryGroups );
|
||||
|
||||
$info = array(
|
||||
'member_id' => $row['USER_ID'],
|
||||
'name' => ( $this->app->_session['more_info']['convertMembers']['username'] == 'user_name' )
|
||||
? $row['USER_LOGIN_NAME']
|
||||
: $row['USER_DISPLAY_NAME'],
|
||||
'email' => $row['USER_REAL_EMAIL'],
|
||||
'md5_password' => $row['USER_PASSWORD'],
|
||||
'member_group_id' => $primaryGroup,
|
||||
'mgroup_others' => $secondaryGroups,
|
||||
'joined' => \IPS\DateTime::create()->setTimestamp( $row['USER_REGISTERED_ON'] ),
|
||||
'ip_address' => $row['USER_REGISTRATION_IP'],
|
||||
'bday_day' => $birthday['day'],
|
||||
'bday_month' => $birthday['month'],
|
||||
'bday_year' => $birthday['year'],
|
||||
'msg_count_total' => $row['USER_TOTAL_PM'],
|
||||
'last_visit' => \IPS\DateTime::create()->setTimestamp( $row['USER_LAST_VISIT_TIME'] ),
|
||||
'last_activity' => \IPS\DateTime::create()->setTimestamp(
|
||||
max( (int) $row['USER_LAST_POST_TIME'], (int) $row['USER_LAST_SEARCH_TIME'] )
|
||||
),
|
||||
'allow_admin_mails' => ( $row['USER_ACCEPT_ADMIN_EMAILS'] != 'Off' ),
|
||||
'member_title' => $row['USER_CUSTOM_TITLE'],
|
||||
'member_posts' => $row['USER_TOTAL_POSTS'],
|
||||
'signature' => $row['USER_DEFAULT_SIGNATURE'],
|
||||
'member_last_post' => \IPS\DateTime::create()->setTimestamp( $row['USER_LAST_POST_TIME'] ),
|
||||
'temp_ban' => isset( $row['BAN_EXPIRATION'] )
|
||||
? ( ( (string) $row['BAN_EXPIRATION'] === '0' )
|
||||
? -1
|
||||
: \IPS\DateTime::create()->setTimestamp( $row['BAN_EXPIRATION'] ) )
|
||||
: NULL,
|
||||
);
|
||||
|
||||
/* Profile fields */
|
||||
$pfields = array();
|
||||
foreach( array( 'homepage', 'occupation', 'hobbies', 'location', 'icq', 'yahoo', 'aim', 'msn' ) AS $pseudo )
|
||||
{
|
||||
/* Are we retaining? */
|
||||
if ( $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"] == 'no_convert' )
|
||||
{
|
||||
/* No, skip */
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
/* We don't actually need this, but we need to make sure the field was created */
|
||||
$fieldId = $this->app->getLink( $pseudo, 'core_pfields_data' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$libraryClass->convertProfileField( array(
|
||||
'pf_id' => $pseudo,
|
||||
'pf_name' => $this->app->_session['more_info']['convertMembers']["field_{$pseudo}"],
|
||||
'pf_desc' => '',
|
||||
'pf_type' => 'Text',
|
||||
'pf_content' => '[]',
|
||||
'pf_member_hide' => 0,
|
||||
'pf_max_input' => 255,
|
||||
'pf_member_edit' => 1,
|
||||
'pf_show_on_reg' => 0,
|
||||
'pf_admin_only' => 0,
|
||||
) );
|
||||
}
|
||||
|
||||
$fieldColumn = 'USER_' . \strtoupper( $pseudo );
|
||||
$pfields[ $pseudo ] = isset( $row[ $fieldColumn ] ) ? $row[ $fieldColumn ] : NULL;
|
||||
}
|
||||
|
||||
/* Profile photo */
|
||||
$profilePhotoName = NULL;
|
||||
$profilePhotoData = NULL;
|
||||
|
||||
if ( !empty( $row['USER_AVATAR'] ) AND ( $row['USER_AVATAR'] != 'http://' ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$profilePhotoName = pathinfo( parse_url( $row['USER_AVATAR'], PHP_URL_PATH ), PATHINFO_BASENAME );
|
||||
$profilePhotoData = \IPS\Http\Url::external( $row['USER_AVATAR'] )->request()->get();
|
||||
}
|
||||
catch( \IPS\Http\Request\Exception $e ) { }
|
||||
}
|
||||
|
||||
$libraryClass->convertMember( $info, $pfields, $profilePhotoName, NULL, $profilePhotoData );
|
||||
$libraryClass->setLastKeyValue( $row['USER_ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert member followers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertMembersFollowers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
foreach ( $this->fetch( 'WATCH_LISTS', 'WATCH_ID', array( 'WATCH_TYPE=?', 'u' ), 'USER_ID ASC, WATCH_ID ASC' ) as $row )
|
||||
{
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'core',
|
||||
'follow_area' => 'member',
|
||||
'follow_rel_id' => $row['WATCH_ID'],
|
||||
'follow_rel_id_type' => 'core_members',
|
||||
'follow_member_id' => $row['USER_ID'],
|
||||
'follow_notify_freq' => $row['WATCH_NOTIFY_IMMEDIATE'] ? 'immediate' : 'none',
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert member ranks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertRanks()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'USER_TITLE_ID' );
|
||||
|
||||
foreach ( $this->fetch( 'USER_TITLES', 'USER_TITLE_ID' ) as $row )
|
||||
{
|
||||
/**
|
||||
* @TODO: We should probably prompt to keep or overwrite existing titles, since this can currently result...
|
||||
* ...in duplicate entries for the same post counts if the local rows are not dropped
|
||||
*/
|
||||
$libraryClass->convertRank( array(
|
||||
'id' => $row['USER_TITLE_ID'],
|
||||
'title' => $row['USER_TITLE_NAME'],
|
||||
'posts' => $row['USER_TITLE_POST_COUNT']
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['USER_TITLE_ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert private messages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'TOPIC_ID' );
|
||||
|
||||
foreach ( $this->fetch( 'PRIVATE_MESSAGE_TOPICS', 'TOPIC_ID' ) as $topicRow )
|
||||
{
|
||||
$topic = array(
|
||||
'mt_id' => $topicRow['TOPIC_ID'],
|
||||
'mt_date' => \IPS\DateTime::create()->setTimestamp( $topicRow['TOPIC_TIME'] ),
|
||||
'mt_title' => $topicRow['TOPIC_SUBJECT'],
|
||||
'mt_starter_id' => $topicRow['USER_ID'],
|
||||
'mt_start_time' => \IPS\DateTime::create()->setTimestamp( $topicRow['TOPIC_TIME'] ),
|
||||
'mt_last_post_time' => \IPS\DateTime::create()->setTimestamp( $topicRow['TOPIC_LAST_REPLY_TIME'] ),
|
||||
'mt_replies' => $topicRow['TOPIC_REPLIES'],
|
||||
);
|
||||
|
||||
$maps = array();
|
||||
|
||||
/* Make sure the topic starter is in the map */
|
||||
$maps[ $topicRow['USER_ID'] ] = array(
|
||||
'map_user_id' => $topicRow['USER_ID'],
|
||||
'map_read_time' => \IPS\DateTime::create()->setTimestamp( $topicRow['TOPIC_TIME'] )
|
||||
);
|
||||
|
||||
foreach ( $this->db->select( '*', 'PRIVATE_MESSAGE_USERS', array( 'TOPIC_ID=?', $topicRow['TOPIC_ID'] ) ) as $userRow )
|
||||
{
|
||||
$maps[ $userRow['USER_ID'] ] = array(
|
||||
'map_user_id' => $userRow['USER_ID'],
|
||||
'map_read_time' => $userRow['MESSAGE_LAST_READ']
|
||||
);
|
||||
}
|
||||
|
||||
$libraryClass->convertPrivateMessage( $topic, $maps );
|
||||
$libraryClass->setLastKeyValue( $topicRow['TOPIC_ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert private message replies
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessageReplies()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'POST_ID' );
|
||||
|
||||
foreach( $this->fetch( 'PRIVATE_MESSAGE_POSTS', 'POST_ID' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertPrivateMessageReply( array(
|
||||
'msg_id' => $row['POST_ID'],
|
||||
'msg_topic_id' => $row['TOPIC_ID'],
|
||||
'msg_date' => \IPS\DateTime::create()->setTimestamp( $row['POST_TIME'] ),
|
||||
'msg_post' => $row['POST_DEFAULT_BODY'],
|
||||
'msg_author_id' => $row['USER_ID'],
|
||||
'msg_ip_address' => '127.0.0.1',
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['POST_ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert profanity filters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertProfanityFilters()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
foreach ( $this->db->select( '*', 'CENSOR_LIST', static::$profanityFiltersWhere ) as $row )
|
||||
{
|
||||
/**
|
||||
* UBB seems to support regex based profanity filters to some extent. We want to avoid converting those,
|
||||
* but if there is a filter that ends with with a wildcard match, we can convert it to a non-exact profanity
|
||||
* filter
|
||||
*/
|
||||
$parsedWord = str_replace( '(.*?)', '', $row['CENSOR_WORD'] );
|
||||
$exact = ( $parsedWord == $row['CENSOR_WORD'] );
|
||||
|
||||
$libraryClass->convertProfanityFilter( array(
|
||||
'wid' => $row['CENSOR_WORD'],
|
||||
'type' => $parsedWord,
|
||||
'swop' => $row['CENSOR_REPLACE_WITH'],
|
||||
'm_exact' => $exact
|
||||
) );
|
||||
}
|
||||
|
||||
throw new \IPS\convert\Software\Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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/users/([0-9]+)#i', $url->data[ \IPS\Http\Url::COMPONENT_PATH ], $matches ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = $this->app->getLink( (int) $matches[1], array( 'members', 'core_members' ) );
|
||||
$item = \IPS\Member::load( $data );
|
||||
|
||||
if( $item->canView() )
|
||||
{
|
||||
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\Core;
|
||||
|
||||
/* 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";
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The activity type ID for status updates
|
||||
*/
|
||||
protected static $activityStatusType = NULL;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \IPS\convert\App The application to reference for database and other information.
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct( \IPS\convert\App $app )
|
||||
{
|
||||
$return = parent::__construct( $app );
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the filesystem location of a file from a path stored in the database
|
||||
* There are several different ways Vanilla may store these, including as remote URL's
|
||||
*
|
||||
* @param $location File location retrieved from the database
|
||||
* @param $uploadsPath Configured uploads path
|
||||
* @return \IPS\Http\Url|string|void
|
||||
*/
|
||||
public static function parseMediaLocation( $location, $uploadsPath )
|
||||
{
|
||||
$uploadsPath = str_replace( '\\', '/', $uploadsPath );
|
||||
|
||||
// URL
|
||||
if ( preg_match( '`^https?://`', $location ) )
|
||||
{
|
||||
return \IPS\Http\Url::external( $location );
|
||||
}
|
||||
// Full filesystem path
|
||||
elseif ( mb_strpos( $location, $uploadsPath ) === 0 )
|
||||
{
|
||||
return $location;
|
||||
}
|
||||
// Deprecated "plugin based" path
|
||||
elseif ( preg_match( '`^~([^/]*)/(.*)$`', $location, $matches ) )
|
||||
{
|
||||
return $uploadsPath.'/'.$matches[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$parts = parse_url( $location );
|
||||
if ( empty( $parts['scheme'] ) )
|
||||
{
|
||||
return $uploadsPath.'/'.$location;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !isset( $parts['path'], $parts['host'] ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// This is a url in the format type:://domain/path.
|
||||
$result = array(
|
||||
'name' => ltrim( $parts['path'], '/'),
|
||||
'type' => $parts['scheme'],
|
||||
'domain' => $parts['host']
|
||||
);
|
||||
|
||||
// @TODO: This is deprecated, and I'm not sure what it was for.
|
||||
#$format = "{$result['type']}://{$result['domain']}/%s";
|
||||
#return sprintf( $format, $result['name'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to convert a MySQL datetime string into a unix timestamp
|
||||
*
|
||||
* @param string $date Date(Time) string
|
||||
* @return int|null Timestamp on successful conversion, otherwise NULL
|
||||
*/
|
||||
public static function mysqlToDateTime( $date )
|
||||
{
|
||||
return \IPS\DateTime::ts( strtotime( $date ) ?: time() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function canConvert()
|
||||
{
|
||||
return array(
|
||||
'convertGroups' => array(
|
||||
'table' => 'Role',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertMembers' => array(
|
||||
'table' => 'User',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertRemoteAvatars' => array(
|
||||
'table' => NULL,
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertStatuses' => array(
|
||||
'table' => 'Activity',
|
||||
'where' => array( 'ActivityTypeId=?', (int) static::$activityStatusType )
|
||||
),
|
||||
'convertPrivateMessages' => array(
|
||||
'table' => 'Conversation',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertPrivateMessageReplies' => array(
|
||||
'table' => 'ConversationMessage',
|
||||
'where' => NULL,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we convert passwords from this software.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function loginEnabled()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a block of text, or a language string, that explains what the admin must do to start this conversion
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPreConversionInformation()
|
||||
{
|
||||
return 'convert_vanilla_preconvert';
|
||||
}
|
||||
|
||||
/**
|
||||
* List of conversion methods that require additional information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
{
|
||||
return array(
|
||||
'convertGroups',
|
||||
'convertMembers'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertGroups':
|
||||
$return['convertGroups'] = array();
|
||||
|
||||
$options = array();
|
||||
$options['none'] = 'None';
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\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' );
|
||||
|
||||
$return['convertGroups']["map_group_{$group['RoleID']}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array( 'options' => $options ),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'convertMembers':
|
||||
$return['convertMembers'] = array();
|
||||
|
||||
/* Find out where the photos live */
|
||||
\IPS\Member::loggedIn()->language()->words['attach_location_desc'] = \IPS\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'),
|
||||
);
|
||||
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()
|
||||
{
|
||||
/* Search Index Rebuild */
|
||||
\IPS\Content\Search\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' ) );
|
||||
|
||||
/* Non-Content Rebuilds */
|
||||
\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' ) );
|
||||
|
||||
/* Content Counts */
|
||||
\IPS\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' ) );
|
||||
|
||||
/* Attachments */
|
||||
\IPS\Task::queue( 'core', 'RebuildAttachmentThumbnails', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
|
||||
|
||||
return array( "f_search_index_rebuild", "f_clear_caches", "f_rebuild_pms", "f_signatures_rebuild", "f_rebuild_attachments" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix post data
|
||||
*
|
||||
* @param string raw post data
|
||||
* @return string parsed post data
|
||||
*/
|
||||
public static function fixPostData( $post )
|
||||
{
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert groups
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGroups()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'r.RoleID' );
|
||||
|
||||
/* Ready Roles */
|
||||
$roles = $this->fetch( array( 'Role', 'r' ), 'RoleID' );
|
||||
//$roles->join( array( 'Permission', 'p' ), 'r.RoleID=p.PermissionID' );
|
||||
|
||||
/* Run conversions */
|
||||
foreach ( $roles as $row )
|
||||
{
|
||||
$info = array(
|
||||
'g_id' => $row['RoleID'],
|
||||
'g_name' => $row['Name'],
|
||||
);
|
||||
$merge = ( $this->app->_session['more_info']['convertGroups']["map_group_{$row['RoleID']}"] != 'none' )
|
||||
? $this->app->_session['more_info']['convertGroups']["map_group_{$row['RoleID']}"]
|
||||
: NULL;
|
||||
|
||||
$libraryClass->convertGroup( $info, $merge );
|
||||
$libraryClass->setLastKeyValue( $row['RoleID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert members
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertMembers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'u.UserID' );
|
||||
|
||||
$uploadsPath = $this->app->_session['more_info']['convertMembers']['attach_location'];
|
||||
|
||||
$users = $this->fetch( array( 'User', 'u' ), 'u.UserID', array( "u.Deleted<>?", 1 ) );
|
||||
$users->join( array( 'UserRole', 'ur' ), 'ur.UserID=u.UserID' );
|
||||
foreach( $users AS $row )
|
||||
{
|
||||
/* Work out birthday */
|
||||
$bdayDay = NULL;
|
||||
$bdayMonth = NULL;
|
||||
$bdayYear = NULL;
|
||||
|
||||
$dateOfBirth = !empty( $row['DateOfBirth'] ) ? @\IPS\DateTime::ts( strtotime( $row['DateOfBirth'] ) ) : NULL;
|
||||
if ( $dateOfBirth instanceof \IPS\DateTime )
|
||||
{
|
||||
$bdayYear = $dateOfBirth->format( 'Y' );
|
||||
$bdayMonth = $dateOfBirth->format( 'n' );
|
||||
$bdayDay = $dateOfBirth->format( 'j' );
|
||||
}
|
||||
|
||||
/* Work out banned stuff */
|
||||
$tempBan = ( $row['Banned'] == 1 ) ? -1 : 0;
|
||||
|
||||
/* Array of basic data */
|
||||
$info = array(
|
||||
'member_id' => $row['UserID'],
|
||||
'email' => $row['Email'],
|
||||
'name' => $row['Name'],
|
||||
'password' => $row['Password'],
|
||||
'member_group_id' => $row['RoleID'] ?: NULL,
|
||||
'joined' => static::mysqlToDateTime( $row['DateInserted'] ),
|
||||
'ip_address' => $row['InsertIPAddress'],
|
||||
'temp_ban' => $tempBan,
|
||||
'bday_day' => $bdayDay,
|
||||
'bday_month' => $bdayMonth,
|
||||
'bday_year' => $bdayYear,
|
||||
'msg_count_new' => (int) $row['CountUnreadDiscussions'],
|
||||
'msg_count_total' => (int) $row['CountDiscussions'],
|
||||
'last_visit' => static::mysqlToDateTime( $row['DateLastActive'] ),
|
||||
'timezone' => !empty( $row['HourOffset'] )
|
||||
? (int) $row['HourOffset']
|
||||
: new \DateTimeZone(
|
||||
'UTC'
|
||||
),
|
||||
'member_posts' => (int) $row['CountComments'],
|
||||
);
|
||||
|
||||
/* Profile Photos */
|
||||
$filepath = NULL;
|
||||
$filename = NULL;
|
||||
|
||||
if ( !empty( $row['Photo'] ) AND ( $location = static::parseMediaLocation( $row['Photo'], $uploadsPath ) ) )
|
||||
{
|
||||
if ( $location instanceof \IPS\Http\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 );
|
||||
$filename = array_pop( $filebits );
|
||||
$filepath = implode( '/', $filebits );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Finally */
|
||||
$libraryClass->convertMember( $info, NULL, $filename, $filepath );
|
||||
$libraryClass->setLastKeyValue( $row['UserID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert statuses
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertStatuses()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'ActivityID' );
|
||||
|
||||
$statuses = $this->fetch( 'Activity', 'ActivityID', array( 'ActivityTypeID=?', static::$activityStatusType ) );
|
||||
|
||||
/* Run conversions */
|
||||
foreach ( $statuses 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
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'ConversationID' );
|
||||
|
||||
$messages = $this->fetch( 'Conversation', 'ConversationID' );
|
||||
|
||||
/* Run conversions */
|
||||
foreach ( $messages as $row )
|
||||
{
|
||||
/* Message topic information */
|
||||
//$firstMessageId = $row['FirstMessageID'];
|
||||
$topicInfo = array(
|
||||
'mt_id' => $row['ConversationID'],
|
||||
'mt_title' => $row['Subject'] ?: NULL,
|
||||
'mt_date' => static::mysqlToDateTime( $row['DateInserted'] ),
|
||||
'mt_starter_id' => $row['InsertUserID'],
|
||||
'mt_last_post_time' => static::mysqlToDateTime( $row['DateUpdated'] ),
|
||||
'mt_to_count' => $row['CountParticipants'],
|
||||
'mt_replies' => $row['CountMessages'],
|
||||
);
|
||||
|
||||
/* Message maps */
|
||||
$maps = array();
|
||||
$rows = $this->fetch( 'UserConversation', 'UserID', array( 'ConversationID=?', $row['ConversationID'] ) );
|
||||
|
||||
foreach ( $rows as $row )
|
||||
{
|
||||
$maps[ $row['UserID'] ] = array(
|
||||
'map_user_id' => $row['UserID'],
|
||||
'map_read_time' => static::mysqlToDateTime( $row['DateLastViewed'] ),
|
||||
//'map_folder_id' => TODO: Create a Bookmarks folder for "Bookmarked" conversations?
|
||||
'map_user_active' => (int) ( $row['Deleted'] != '0' ),
|
||||
'map_last_topic_reply' => static::mysqlToDateTime( $row['DateConversationUpdated'] )
|
||||
);
|
||||
}
|
||||
|
||||
$libraryClass->convertPrivateMessage( $topicInfo, $maps );
|
||||
$libraryClass->setLastKeyValue( $row['MessageID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert PM replies
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertPrivateMessageReplies()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'MessageID' );
|
||||
|
||||
foreach( $this->fetch( 'ConversationMessage', 'MessageID' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertPrivateMessageReply( array(
|
||||
'msg_id' => $row['MessageID'],
|
||||
'msg_topic_id' => $row['ConversationID'],
|
||||
'msg_date' => static::mysqlToDateTime( $row['DateInserted'] ),
|
||||
'msg_post' => $row['Body'],
|
||||
'msg_author_id' => $row['InsertUserID'],
|
||||
'msg_ip_address' => $row['InsertIPAddress']
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['MessageID'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter Wordpress Core 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 12 December 2015
|
||||
*/
|
||||
|
||||
namespace IPS\convert\Software\Core;
|
||||
|
||||
/* 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 _Wordpress extends \IPS\convert\Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "WordPress (4.x)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "wordpress";
|
||||
}
|
||||
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function canConvert()
|
||||
{
|
||||
return array(
|
||||
'convertMembers' => array(
|
||||
'table' => 'users',
|
||||
'where' => NULL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we convert passwords from this software.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function loginEnabled()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a block of text, or a language string, that explains what the admin must do to start this conversion
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPreConversionInformation()
|
||||
{
|
||||
return 'convert_wordpress_preconvert';
|
||||
}
|
||||
|
||||
/**
|
||||
* List of conversion methods that require additional information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
{
|
||||
return array(
|
||||
'convertMembers',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix post data
|
||||
*
|
||||
* @param string raw post data
|
||||
* @return string parsed post data
|
||||
*/
|
||||
public static function fixPostData( $post )
|
||||
{
|
||||
return nl2br( $post );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertMembers':
|
||||
$return['convertMembers']['username'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Radio',
|
||||
'field_default' => 'display_name',
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array( 'options' => array( 'username' => \IPS\Member::loggedIn()->language()->addToStack( 'user_name' ), 'display_name' => \IPS\Member::loggedIn()->language()->addToStack( 'display_name' ) ) ),
|
||||
'field_hint' => \IPS\Member::loggedIn()->language()->addToStack( 'username_hint' ),
|
||||
);
|
||||
|
||||
/* Pseudo Fieds */
|
||||
foreach( array( 'first_name', 'last_name', 'user_url' ) AS $field )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field', FALSE, array( 'sprintf' => ucwords( str_replace( '_', ' ', $field ) ) ) );
|
||||
\IPS\Member::loggedIn()->language()->words["field_{$field}_desc"] = \IPS\Member::loggedIn()->language()->addToStack( 'pseudo_field_desc' );
|
||||
$return['convertMembers']["field_{$field}"] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Radio',
|
||||
'field_default' => 'no_convert',
|
||||
'field_required' => TRUE,
|
||||
'field_extra' => array(
|
||||
'options' => array(
|
||||
'no_convert' => \IPS\Member::loggedIn()->language()->addToStack( 'no_convert' ),
|
||||
'create_field' => \IPS\Member::loggedIn()->language()->addToStack( 'create_field' ),
|
||||
),
|
||||
'userSuppliedInput' => 'create_field'
|
||||
),
|
||||
'field_hint' => NULL
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert members
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertMembers()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'users.ID' );
|
||||
|
||||
foreach( $this->fetch( 'users', 'users.ID', NULL, 'users.*, usermeta.meta_value as user_level' )->join( 'usermeta', "users.ID=usermeta.user_id AND usermeta.meta_key='wp_user_level'" ) AS $user )
|
||||
{
|
||||
/* Main Members Table */
|
||||
$info = array(
|
||||
'member_id' => $user['ID'],
|
||||
'ips_group_id' => $user['user_level'] > 9 ? \IPS\Settings::i()->admin_group : \IPS\Settings::i()->member_group,
|
||||
'name' => $this->app->_session['more_info']['convertMembers']['username'] == 'username' ? $user['user_login'] : $user['display_name'],
|
||||
'email' => $user['user_email'],
|
||||
'joined' => new \IPS\DateTime( $user['user_registered'] ),
|
||||
'conv_password' => $user['user_pass'],
|
||||
'pp_photo_type' => 'gravatar',
|
||||
'pp_gravatar' => $user['user_email'], # WordPress always uses gravatar, as it's their service
|
||||
);
|
||||
|
||||
$fields = array();
|
||||
foreach( array( 'first_name', 'last_name', 'user_url' ) AS $field )
|
||||
{
|
||||
if ( $this->app->_session['more_info']['convertMembers']["field_{$field}"] != 'no_convert' )
|
||||
{
|
||||
try
|
||||
{
|
||||
$fieldId = $this->app->getLink( $field, 'core_pfields_data' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$libraryClass->convertProfileField( array(
|
||||
'pf_id' => $field,
|
||||
'pf_name' => $this->app->_session['more_info']['convertMembers']["field_{$field}"],
|
||||
'pf_desc' => '',
|
||||
'pf_type' => 'Text',
|
||||
'pf_content' => '[]',
|
||||
'pf_member_hide' => 0,
|
||||
'pf_max_input' => 255,
|
||||
'pf_member_edit' => 1,
|
||||
'pf_show_on_reg' => 0,
|
||||
'pf_admin_only' => 0,
|
||||
) );
|
||||
}
|
||||
|
||||
if ( isset( $user[$field] ) )
|
||||
{
|
||||
$fields[$field] = $user[$field];
|
||||
}
|
||||
else
|
||||
{
|
||||
$fields[$field] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$libraryClass->convertMember( $info, $fields );
|
||||
$libraryClass->setLastKeyValue( $user['ID'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish - Adds everything it needs to the queues and clears data store
|
||||
*
|
||||
* @return array Messages to display
|
||||
*/
|
||||
public function finish()
|
||||
{
|
||||
/* Search Index Rebuild */
|
||||
\IPS\Content\Search\Index::i()->rebuild();
|
||||
|
||||
/* Clear Cache and Store */
|
||||
\IPS\Data\Store::i()->clearAll();
|
||||
\IPS\Data\Cache::i()->clearAll();
|
||||
|
||||
/* Content Counts */
|
||||
\IPS\Task::queue( 'core', 'RecountMemberContent', array( 'app' => $this->app->app_id ), 4, array( 'app' ) );
|
||||
|
||||
return array( "f_search_index_rebuild", "f_clear_caches" );
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,491 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter XenForo Resource Manager 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\Downloads;
|
||||
|
||||
/* 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
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "XenForo Resource Manager";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'convertDownloadsCfields' => array(
|
||||
'table' => 'xf_resource_field',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertDownloadsCategories' => array(
|
||||
'table' => 'xf_resource_category',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertDownloadsFiles' => array(
|
||||
'table' => 'xf_resource',
|
||||
'where' => array( "is_fileless=?", 0 )
|
||||
),
|
||||
'convertDownloadsReviews' => array(
|
||||
'table' => 'xf_resource_rating',
|
||||
'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( 'xenforo' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* List of conversion methods that require additional information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
{
|
||||
return array(
|
||||
'convertDownloadsFiles',
|
||||
'convertDownloadsReviews'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertDownloadsFiles':
|
||||
$return['convertDownloadsFiles']['file_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;
|
||||
|
||||
case 'convertDownloadsReviews':
|
||||
$return['convertDownloadsReviews']['convert_author_replies_to_comments'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\YesNo',
|
||||
'field_default' => FALSE,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array(),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
}
|
||||
|
||||
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 custom fields
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertDownloadsCfields()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
foreach( $this->fetch( 'xf_resource_field', 'field_id' ) AS $row )
|
||||
{
|
||||
$info = array(
|
||||
'cf_id' => $row['field_id'],
|
||||
'cf_type' => $this->_mapFieldType( $row['field_type'], $row['match_type'] ),
|
||||
'cf_content' => \unserialize( $row['field_choices'] ),
|
||||
'cf_not_null' => $row['required'],
|
||||
'cf_max_input' => $row['max_length'],
|
||||
'cf_input_format' => ( $row['match_type'] == 'regex' ) ? '/' . $row['match_regex'] .'/i' : '',
|
||||
'cf_position' => $row['display_order'],
|
||||
'cf_multiple' => ( in_array( $row['field_type'], array( 'checkbox', 'multiselect' ) ) ) ? 1 : 0
|
||||
);
|
||||
|
||||
$libraryClass->convertDownloadsCfield( $info );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the field types
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _mapFieldType( $type, $match )
|
||||
{
|
||||
switch( $type )
|
||||
{
|
||||
case 'textbox':
|
||||
/* Yay, nested switches */
|
||||
switch( $match )
|
||||
{
|
||||
case 'email':
|
||||
return 'Email';
|
||||
break;
|
||||
|
||||
case 'url':
|
||||
return 'Url';
|
||||
break;
|
||||
|
||||
case 'number':
|
||||
return 'Number';
|
||||
break;
|
||||
|
||||
default:
|
||||
return 'Text';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'textarea':
|
||||
return 'TextArea';
|
||||
break;
|
||||
|
||||
case 'bbcode':
|
||||
return 'Editor';
|
||||
break;
|
||||
|
||||
case 'multiselect':
|
||||
case 'select':
|
||||
return 'Select';
|
||||
break;
|
||||
|
||||
case 'checkbox':
|
||||
return 'CheckboxSet';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert categories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertDownloadsCategories()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'resource_category_id' );
|
||||
|
||||
foreach( $this->fetch( 'xf_resource_category', 'resource_category_id' ) AS $row )
|
||||
{
|
||||
/* Custom Fields for this category */
|
||||
$ccfields = array();
|
||||
foreach( $this->db->select( 'field_id', 'xf_resource_field_category', array( "resource_category_id=?", $row['resource_category_id'] ) ) AS $field )
|
||||
{
|
||||
$ccfields[] = $field;
|
||||
}
|
||||
|
||||
/* Topic Prefix */
|
||||
$prefix = '';
|
||||
if ( $row['thread_prefix_id'] AND $row['thread_node_id'] )
|
||||
{
|
||||
$prefix = $this->getPhrase( "thread_prefix_{$row['thread_prefix_id']}" );
|
||||
|
||||
if ( is_null( $prefix ) )
|
||||
{
|
||||
$prefix = '';
|
||||
}
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'cid' => $row['resource_category_id'],
|
||||
'cparent' => $row['parent_category_id'],
|
||||
'cname' => $row['category_title'],
|
||||
'cdesc' => $row['category_description'],
|
||||
'copen' => ( $row['allow_local'] OR $row['allow_external'] ) ? 1 : 0,
|
||||
'cposition' => $row['display_order'],
|
||||
'ccfields' => $ccfields,
|
||||
'cforum_id' => $row['thread_node_id'],
|
||||
'ctopic_prefix' => $prefix
|
||||
);
|
||||
|
||||
$libraryClass->convertDownloadsCategory( $info );
|
||||
|
||||
/* Follows */
|
||||
foreach( $this->db->select( '*', 'xf_resource_category_watch', array( "notify_on=? AND resource_category_id=?", 'resource', $row['resource_category_id'] ) ) AS $follow )
|
||||
{
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'downloads',
|
||||
'follow_area' => 'category',
|
||||
'follow_rel_id' => $row['resource_category_id'],
|
||||
'follow_rel_id_type' => 'downloads_categories',
|
||||
'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['resource_category_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert files
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertDownloadsFiles()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'resource_id' );
|
||||
|
||||
foreach( $this->fetch( 'xf_resource', 'resource_id', array( "is_fileless=?", 0 ) ) AS $row )
|
||||
{
|
||||
/* Latest Version Stuff */
|
||||
$latest = $this->db->select( '*', 'xf_resource_update', array( "xf_resource_update.resource_id=?", $row['resource_id'] ), "xf_resource_update.post_date DESC" )
|
||||
->join( 'xf_resource_version', "xf_resource_update.resource_update_id = xf_resource_version.resource_update_id" )
|
||||
->first();
|
||||
|
||||
$latest_version = $latest['version_string'];
|
||||
$latest_changelog = $latest['message'];
|
||||
|
||||
/* Featured */
|
||||
$featured = 0;
|
||||
try
|
||||
{
|
||||
$this->db->select( '*', 'xf_resource_feature', array( "resource_id=?", $row['resource_id'] ) )->first();
|
||||
|
||||
$featured = 1;
|
||||
}
|
||||
catch( \UnderflowExceptioN $e ) {}
|
||||
|
||||
$info = array(
|
||||
'file_id' => $row['resource_id'],
|
||||
'file_desc' => $row['tag_line'],
|
||||
'file_name' => $row['title'],
|
||||
'file_cat' => $row['resource_category_id'],
|
||||
'file_downloads' => $this->db->select( 'COUNT(*)', 'xf_resource_download', array( 'resource_id=?', $row['resource_id'] ) )->first(),
|
||||
'file_reviews' => $row['review_count'],
|
||||
'file_submitted' => $row['resource_date'],
|
||||
'file_updated' => $row['last_update'],
|
||||
'file_submitter' => $row['user_id'],
|
||||
'file_topicid' => $row['discussion_thread_id'],
|
||||
'file_version' => $latest_version,
|
||||
'file_changelog' => $latest_changelog,
|
||||
'file_featured' => $featured,
|
||||
);
|
||||
|
||||
$records = array();
|
||||
$recordit = $this->db->select( '*', 'xf_resource_update', array( "xf_resource_update.resource_id=?", $row['resource_id'] ) )->join( 'xf_resource_version', "xf_resource_update.resource_update_id = xf_resource_version.resource_update_id" );
|
||||
foreach( $recordit AS $record )
|
||||
{
|
||||
if ( $record['download_url'] )
|
||||
{
|
||||
$records[] = array(
|
||||
'record_id' => $record['resource_update_id'],
|
||||
'record_type' => 'link',
|
||||
'file_path' => $record['download_url'],
|
||||
'record_time' => $record['release_date']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$file_data = $this->db->select( '*', 'xf_attachment', array( "xf_attachment.content_type=? AND xf_attachment.content_id=?", 'resource_version', $record['resource_version_id'] ) )->join( 'xf_attachment_data', "xf_attachment.data_id = xf_attachment_data.data_id" )->first();
|
||||
$group = floor( $row['user_id'] / 1000 );
|
||||
|
||||
$records[] = array(
|
||||
'record_id' => $record['resource_update_id'],
|
||||
'record_type' => 'upload',
|
||||
'file_path' => rtrim( $this->app->_session['more_info']['convertDownloadsFiles']['file_location'], '/' ) . '/' . $group . '/' . $file_data['data_id'] . '-' . $file_data['file_hash'] . '.data',
|
||||
'record_time' => $record['release_date']
|
||||
);
|
||||
}
|
||||
|
||||
/* And now screenshots */
|
||||
foreach( $this->db->select( '*', 'xf_attachment', array( "xf_attachment.content_type=? AND xf_attachment.content_id=?", 'resource_update', $record['resource_update_id'] ) )->join( 'xf_attachment_data', "xf_attachment.data_id = xf_attachment_data.data_id" ) AS $screen )
|
||||
{
|
||||
$group = floor( $row['user_id'] / 1000 );
|
||||
|
||||
$records[] = array(
|
||||
'record_type' => 'ssupload',
|
||||
'file_path' => rtrim( $this->app->_session['more_info']['convertDownloadsFiles']['file_location'], '/' ) . '/' . $group . '/' . $screen['data_id'] . '-' . $screen['file_hash'] . '.data',
|
||||
'record_time' => $record['release_date']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$cfields = array();
|
||||
foreach( $this->db->select( 'field_id, field_value', 'xf_resource_field_value', array( "resource_id=?", $row['resource_id'] ) )->setKeyField( 'field_id' )->setValueField( 'field_value' ) AS $key => $value )
|
||||
{
|
||||
$field_type = $this->db->select( 'field_type', 'xf_resource_field', array( "field_id=?", $key ) )->first();
|
||||
|
||||
if ( in_array( $field_type, array( 'checkbox', 'multiselect' ) ) )
|
||||
{
|
||||
$cfields[$key] = json_encode( \unserialize( $value ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$cfields[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$libraryClass->convertDownloadsFile( $info, $records, $cfields );
|
||||
|
||||
/* Follows */
|
||||
foreach( $this->db->select( '*', 'xf_resource_watch', array( "resource_id=?", $row['resource_id'] ) ) AS $follow )
|
||||
{
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'downloads',
|
||||
'follow_area' => 'file',
|
||||
'follow_rel_id' => $row['resource_id'],
|
||||
'follow_rel_id_type' => 'downloads_files',
|
||||
'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
|
||||
) );
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['resource_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert reviews
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertDownloadsReviews()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'resource_rating_id' );
|
||||
|
||||
foreach( $this->fetch( 'xf_resource_rating', 'resource_rating_id' ) AS $row )
|
||||
{
|
||||
switch( $row['rating_state'] )
|
||||
{
|
||||
case 'visible':
|
||||
$approved = 1;
|
||||
break;
|
||||
|
||||
case 'moderated':
|
||||
$approved = 0;
|
||||
break;
|
||||
|
||||
case 'deleted':
|
||||
$approved = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'review_id' => $row['resource_rating_id'],
|
||||
'review_text' => $row['message'],
|
||||
'review_rating' => $row['rating'],
|
||||
'review_mid' => $row['user_id'],
|
||||
'review_fid' => $row['resource_id'],
|
||||
'review_date' => $row['rating_date'],
|
||||
'review_approved' => $approved,
|
||||
'review_version' => $row['version_string']
|
||||
);
|
||||
|
||||
$libraryClass->convertDownloadsReview( $info );
|
||||
|
||||
if ( $this->app->_session['more_info']['convertDownloadsReviews']['convert_author_replies_to_comments'] AND $row['author_response'] )
|
||||
{
|
||||
/* Get Resource */
|
||||
$resource = $this->db->select( '*', 'xf_resource', array( "resource_id=?", $row['resource_id'] ) )->first();
|
||||
$member = $this->db->select( '*', 'xf_user', array( "user_id=?", $row['user_id'] ) )->first();
|
||||
$post = "<blockquote class=\"ipsQuote\" data-ipsQuote-username=\"{$member['username']}\">{$row['message']}</blockquote><p>{$row['author_response']}</p>";
|
||||
|
||||
$libraryClass->convertDownloadsComment( array(
|
||||
'comment_id' => $row['resource_rating_id'],
|
||||
'comment_fid' => $row['resource_id'],
|
||||
'comment_text' => $post,
|
||||
'comment_mid' => $resource['user_id'],
|
||||
'comment_date' => $row['rating_date'],
|
||||
) );
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['resource_rating_id'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Software Exception 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;
|
||||
|
||||
/* 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 _Exception extends \OutOfRangeException
|
||||
{}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter Coppermine Gallery 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\Gallery;
|
||||
|
||||
/* 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 _Coppermine extends \IPS\convert\Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "Coppermine";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "coppermine";
|
||||
}
|
||||
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function canConvert()
|
||||
{
|
||||
return array(
|
||||
'convertGalleryCategories' => array(
|
||||
'table' => 'categories',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertGalleryAlbums' => array(
|
||||
'table' => 'albums',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertGalleryImages' => array(
|
||||
'table' => 'pictures',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertGalleryComments' => array(
|
||||
'table' => 'comments',
|
||||
'where' => NULL,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible Parent Conversions
|
||||
*
|
||||
* @return NULL|array
|
||||
*/
|
||||
public static function parents()
|
||||
{
|
||||
return array( 'core' => array( 'phpbb' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* List of conversion methods that require additional information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
{
|
||||
return array(
|
||||
'convertGalleryAlbums',
|
||||
'convertGalleryImages'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Method name
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertGalleryAlbums':
|
||||
$options = array();
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'gallery_categories' ), 'IPS\gallery\Category' ) AS $category )
|
||||
{
|
||||
$options[$category->_id] = $category->_title;
|
||||
}
|
||||
|
||||
$return['convertGalleryAlbums']['members_gallery_category'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array(
|
||||
'options' => $options
|
||||
),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
break;
|
||||
case 'convertGalleryImages':
|
||||
$return['convertGalleryImages']['file_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_coppermine_filehint' ),
|
||||
'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( 'convert', 'RebuildGalleryImages', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\gallery\Image' ), 3, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Album', 'count' => 0 ), 4, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Category', 'count' => 0 ), 5, array( 'class' ) );
|
||||
|
||||
/* Caches */
|
||||
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'gallery_images', 'class' => 'IPS\gallery\Image' ), 3, array( 'app', 'link', 'class' ) );
|
||||
|
||||
return array( "f_gallery_images_rebuild", "f_gallery_cat_recount", "f_gallery_album_recount", "f_gallery_image_recount", "f_image_tags_recount" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert categories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryCategories()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'cid' );
|
||||
|
||||
foreach( $this->fetch( 'categories', 'cid' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertGalleryCategory( array(
|
||||
'category_id' => $row['cid'],
|
||||
'category_name' => $row['name'],
|
||||
'category_desc' => $row['description'],
|
||||
'category_parent_id' => $row['parent'],
|
||||
'category_position' => $row['pos']
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['cid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert albums
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryAlbums()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'aid' );
|
||||
|
||||
foreach( $this->fetch( 'albums', 'aid' ) AS $row )
|
||||
{
|
||||
$info = array(
|
||||
'album_id' => $row['aid'],
|
||||
'album_owner_id' => isset( $row['owner'] ) ? $row['owner'] : NULL,
|
||||
'album_category_id' => $row['category'],
|
||||
'album_description' => $row['description'],
|
||||
'album_position' => $row['pos'],
|
||||
'album_name' => $row['title'],
|
||||
'album_allow_comments' => ( $row['comments'] == 'YES' ),
|
||||
'album_allow_reviews' => ( $row['comments'] == 'YES' ),
|
||||
'album_allow_rating' => ( $row['votes'] == 'YES' )
|
||||
);
|
||||
|
||||
$category = NULL;
|
||||
try
|
||||
{
|
||||
$this->app->getLink( $row['category'], 'gallery_categories' );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
$category = $this->app->_session['more_info']['convertGalleryAlbums']['members_gallery_category'];
|
||||
if ( $category == 0 )
|
||||
{
|
||||
$category = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$libraryClass->convertGalleryAlbum( $info, NULL, $category );
|
||||
$libraryClass->setLastKeyValue( $row['aid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert images
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryImages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'pid' );
|
||||
|
||||
foreach( $this->fetch( 'pictures', 'pid' ) AS $row )
|
||||
{
|
||||
$info = array(
|
||||
'image_id' => $row['pid'],
|
||||
'image_album_id' => $row['aid'],
|
||||
'image_member_id' => $row['owner_id'],
|
||||
/* Some images in the test data don't have titles, use filename if title is missing */
|
||||
'image_caption' => $row['title'] ?: $row['filename'],
|
||||
'image_description' => $row['caption'],
|
||||
'image_views' => $row['hits'],
|
||||
'image_date' => $row['ctime'],
|
||||
'image_updated' => \strtotime( $row['mtime'] ),
|
||||
'image_ipaddress' => $row['pic_raw_ip'],
|
||||
'image_file_name' => $row['filename']
|
||||
);
|
||||
|
||||
/* Filepath */
|
||||
$path = rtrim( $this->app->_session['more_info']['convertGalleryImages']['file_location'], '/' ) . '/' . $row['filepath'] . '/' . $row['filename'];
|
||||
|
||||
$libraryClass->convertGalleryImage( $info, $path );
|
||||
|
||||
/* Tags */
|
||||
if( !empty( $row['keywords'] ) )
|
||||
{
|
||||
$keywords = explode( ' ', $row['keywords'] );
|
||||
foreach( $keywords as $key )
|
||||
{
|
||||
$word = explode( ',', $key );
|
||||
|
||||
foreach( $word as $w )
|
||||
{
|
||||
$libraryClass->convertTag( array(
|
||||
'tag_meta_app' => 'gallery',
|
||||
'tag_meta_area' => 'gallery',
|
||||
'tag_meta_parent_id' => $row['aid'],
|
||||
'tag_meta_id' => $row['pid'],
|
||||
'tag_text' => $w,
|
||||
'tag_prefix' => 0,
|
||||
'tag_member_id' => $row['owner_id']
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['pid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert comments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryComments()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'msg_id' );
|
||||
|
||||
foreach( $this->fetch( 'comments', 'msg_id' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertGalleryComment( array(
|
||||
'comment_id' => $row['msg_id'],
|
||||
'comment_text' => $row['msg_body'],
|
||||
'comment_img_id' => $row['pid'],
|
||||
'comment_author_id' => $row['author_id'],
|
||||
'comment_author_name' => $row['msg_author'],
|
||||
'comment_ip_address' => $row['msg_raw_ip'],
|
||||
'comment_post_date' => \strtotime( $row['msg_date'] ),
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['msg_id'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter PhotoPlog Gallery 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 02 October 2016
|
||||
*/
|
||||
|
||||
namespace IPS\convert\Software\Gallery;
|
||||
|
||||
/* 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 _Photoplog extends \IPS\convert\Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "PhotoPlog (vBulletin 3.x/4.x)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "photoplog";
|
||||
}
|
||||
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function canConvert()
|
||||
{
|
||||
return array(
|
||||
'convertGalleryCategories' => array(
|
||||
'table' => 'categories',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertGalleryAlbums'=> array(
|
||||
'table' => 'useralbums',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertGalleryImages' => array(
|
||||
'table' => 'fileuploads',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertGalleryComments' => array(
|
||||
'table' => 'ratecomment',
|
||||
'where' => array( "rating=?", 0 )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires Parent
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function requiresParent()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible Parent Conversions
|
||||
*
|
||||
* @return NULL|array
|
||||
*/
|
||||
public static function parents()
|
||||
{
|
||||
return array( 'core' => array( 'vbulletin' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* List of conversion methods that require additional information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
{
|
||||
return array(
|
||||
'convertGalleryAlbums',
|
||||
'convertGalleryImages'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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( 'convert', 'RebuildGalleryImages', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\gallery\Image' ), 3, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Album', 'count' => 0 ), 4, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Category', 'count' => 0 ), 5, array( 'class' ) );
|
||||
|
||||
return array( "f_gallery_images_rebuild", "f_gallery_cat_recount", "f_gallery_album_recount", "f_gallery_image_recount" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Method name
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertGalleryAlbums':
|
||||
$options = array();
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'gallery_categories' ), 'IPS\gallery\Category' ) AS $category )
|
||||
{
|
||||
$options[ $category->_id ] = $category->_title;
|
||||
}
|
||||
|
||||
$return['convertGalleryAlbums']['members_gallery_category'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array(
|
||||
'options' => $options
|
||||
),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
break;
|
||||
case 'convertGalleryImages':
|
||||
$return['convertGalleryImages']['file_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_photoplog_hint'),
|
||||
'field_validation' => function( $value ) { if ( !@is_dir( $value ) ) { throw new \DomainException( 'path_invalid' ); } },
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Photoplog Albums
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryAlbums()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'albumid' );
|
||||
|
||||
foreach( $this->fetch( 'useralbums', 'albumid' ) AS $row )
|
||||
{
|
||||
$info = array(
|
||||
'album_id' => $row['albumid'],
|
||||
'album_owner_id' => $row['userid'],
|
||||
'album_description' => $row['description'],
|
||||
'album_name' => $row['title'],
|
||||
'album_type' => $row['visible'] ?: 0
|
||||
);
|
||||
|
||||
$category = $this->app->_session['more_info']['convertGalleryAlbums']['members_gallery_category'];
|
||||
if ( $category == 0 )
|
||||
{
|
||||
$category = NULL;
|
||||
}
|
||||
|
||||
$libraryClass->convertGalleryAlbum( $info, NULL, $category );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['albumid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Photoplog Categories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryCategories()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'catid' );
|
||||
|
||||
foreach( $this->fetch( 'categories', 'catid' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertGalleryCategory( array(
|
||||
'category_id' => $row['catid'],
|
||||
'category_name' => $row['title'],
|
||||
'category_desc' => $row['description'],
|
||||
'category_parent_id' => $row['parentid'] > 0 ? $row['parentid'] : 0,
|
||||
'category_position' => $row['displayorder']
|
||||
) );
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['catid'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Photoplog Images
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryImages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
$libraryClass::setKey( 'fileid' );
|
||||
|
||||
foreach( $this->fetch( 'fileuploads', 'fileid' ) AS $row )
|
||||
{
|
||||
$album = \unserialize( $row['albumids'] );
|
||||
$albumId = NULL;
|
||||
|
||||
if( is_array( $album ) )
|
||||
{
|
||||
$albumId = $album[0];
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'image_id' => $row['fileid'],
|
||||
'image_album_id' => $albumId,
|
||||
'image_category_id' => $row['catid'],
|
||||
'image_member_id' => $row['userid'],
|
||||
'image_caption' => $row['title'],
|
||||
'image_views' => $row['views'],
|
||||
'image_comments' => $row['num_comments0'] + $row['num_comments1'],
|
||||
'image_ratings_total' => $row['sum_ratings1'],
|
||||
'image_ratings_count' => $row['num_ratings1'],
|
||||
'image_rating' => $row['num_ratings1'] > 0 ? intval( $row['sum_ratings1'] / $row['num_ratings1'] ) : 0,
|
||||
'image_date' => $row['dateline'],
|
||||
'image_metadata' => json_encode( \unserialize( $row['exifinfo'] ) ),
|
||||
'image_file_name' => $row['filename'],
|
||||
'image_description' => $row['description'],
|
||||
'image_approved' => $row['moderate'] == 1 ? 0 : 1,
|
||||
);
|
||||
|
||||
$libraryClass->convertGalleryImage( $info, rtrim( $this->app->_session['more_info']['convertGalleryImages']['file_location'], '/' ) . '/' . $row['userid'] . '/' . $row['filename'] );
|
||||
|
||||
/* Ratings! */
|
||||
foreach( $this->db->select( '*', 'ratecomment', array( "fileid=? AND rating>0", $row['fileid'] ) ) AS $rating )
|
||||
{
|
||||
$libraryClass->convertRating( array(
|
||||
'id' => $rating['commentid'],
|
||||
'class' => 'IPS\gallery\Image',
|
||||
'item_link' => 'gallery_images',
|
||||
'item_id' => $row['fileid'],
|
||||
'rating' => $rating['rating'],
|
||||
'member' => $rating['userid'],
|
||||
) );
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['fileid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Photoplog Comments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryComments()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'commentid' );
|
||||
|
||||
foreach( $this->fetch( 'ratecomment', 'commentid', array( "rating=?", 0 ) ) AS $row )
|
||||
{
|
||||
$libraryClass->convertGalleryComment( array(
|
||||
'comment_id' => $row['commentid'],
|
||||
'comment_text' => $row['comment'],
|
||||
'comment_img_id' => $row['fileid'],
|
||||
'comment_author_id' => $row['userid'],
|
||||
'comment_author_name' => $row['username'],
|
||||
'comment_post_date' => $row['dateline'],
|
||||
'comment_approved' => ( $row['moderate'] == 1 ) ? 0 : 1,
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['commentid'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter Photopost Gallery 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\Gallery;
|
||||
|
||||
/* 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 _Photopost extends \IPS\convert\Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "Photopost";
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "photopost";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ], 'showgallery.php' ) !== FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = (string) $this->app->getLink( \IPS\Request::i()->cat, 'gallery_categories' );
|
||||
$item = \IPS\gallery\Category::load( $data );
|
||||
|
||||
if( $item->can('view') )
|
||||
{
|
||||
return $item->url();
|
||||
}
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'showphoto.php' ) !== FALSE )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = (string) $this->app->getLink( \IPS\Request::i()->photo, 'gallery_images' );
|
||||
$item = \IPS\gallery\Image::load( $data );
|
||||
|
||||
if( $item->canView() )
|
||||
{
|
||||
return $item->url();
|
||||
}
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,481 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter vBulletin 4.x Gallery 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\Gallery;
|
||||
|
||||
/* 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 $imageContentType = NULL;
|
||||
|
||||
/**
|
||||
* @brief The schematic for vB3 and vB4 is similar enough that we can make specific concessions in a sinle converter for either version.
|
||||
*/
|
||||
protected static $isLegacy = NULL;
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
/* Is this vB3 or vB4? */
|
||||
if ( $needDB )
|
||||
{
|
||||
try
|
||||
{
|
||||
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::$imageContentType === NULL AND ( static::$isLegacy === FALSE OR is_null( static::$isLegacy ) ) )
|
||||
{
|
||||
static::$imageContentType = $this->db->select( 'contenttypeid', 'contenttype', array( "class=?", 'Album' ) )->first();
|
||||
}
|
||||
}
|
||||
catch( \Exception $e ) {}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "vBulletin Gallery (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()
|
||||
{
|
||||
$imageWhere = NULL;
|
||||
$imageTable = 'picture';
|
||||
|
||||
if ( static::$isLegacy == FALSE )
|
||||
{
|
||||
$imageWhere = array( "contenttypeid=?", static::$imageContentType );
|
||||
$imageTable = 'attachment';
|
||||
}
|
||||
|
||||
return array(
|
||||
'convertGalleryAlbums'=> array(
|
||||
'table' => 'album',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertGalleryImages' => array(
|
||||
'table' => $imageTable,
|
||||
'where' => $imageWhere
|
||||
),
|
||||
'convertGalleryComments' => array(
|
||||
'table' => 'picturecomment',
|
||||
'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( '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( 'convert', 'RebuildGalleryImages', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\gallery\Image' ), 3, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Album', 'count' => 0 ), 4, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Category', 'count' => 0 ), 5, array( 'class' ) );
|
||||
|
||||
/* Caches */
|
||||
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'gallery_images', 'class' => 'IPS\gallery\Image' ), 3, array( 'app', 'link', 'class' ) );
|
||||
|
||||
return array( "f_gallery_images_rebuild", "f_gallery_cat_recount", "f_gallery_album_recount", "f_gallery_image_recount", "f_image_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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertGalleryImages':
|
||||
$return['convertGalleryImages'] = 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,
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return ( isset( $return[ $method ] ) ) ? $return[ $method ] : array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List of conversion methods that require additional information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
{
|
||||
return array( 'convertGalleryImages' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert gallery albums
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryAlbums()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'albumid' );
|
||||
|
||||
foreach( $this->fetch( 'album', 'albumid' ) AS $album )
|
||||
{
|
||||
$socialgroup = NULL;
|
||||
if ( $album['state'] == 'private' )
|
||||
{
|
||||
/* Fetch users friends */
|
||||
$friends = array();
|
||||
foreach( $this->db->select( 'relationid', 'userlist', array( "userid=?", $album['userid'] ) ) AS $friend )
|
||||
{
|
||||
$friends[$friend] = $friend;
|
||||
}
|
||||
|
||||
$socialgroup = array( 'members' => $friends );
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'album_id' => $album['albumid'],
|
||||
'album_owner_id' => $album['userid'],
|
||||
'album_name' => $album['title'],
|
||||
'album_description' => $album['description'],
|
||||
'album_type' => ( $album['state'] == 'private' ) ? 3 : 1,
|
||||
'album_count_imgs' => $album['visible'],
|
||||
'album_count_imgs_hidden' => $album['moderation'],
|
||||
'album_last_img_date' => $album['lastpicturedate']
|
||||
);
|
||||
|
||||
$libraryClass->convertGalleryAlbum( $info, $socialgroup );
|
||||
|
||||
$libraryClass->setLastKeyValue( $album['albumid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert gallery images
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryImages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
/* Don't even bother trying to swap things out - just do different things based on version */
|
||||
if ( static::$isLegacy === TRUE )
|
||||
{
|
||||
$libraryClass::setKey( 'pictureid' );
|
||||
|
||||
foreach( $this->fetch( 'picture', 'pictureid' ) AS $image )
|
||||
{
|
||||
$filedata = NULL;
|
||||
$filepath = NULL;
|
||||
|
||||
if ( $this->app->_session['more_info']['convertGalleryImages']['file_location'] == 'database' )
|
||||
{
|
||||
/* Simples! */
|
||||
$filedata = $image['filedata'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$filepath = floor( $image['pictureid'] / 1000 );
|
||||
$filepath = rtrim( $this->app->_session['more_info']['convertGalleryImages']['file_location'], '/' ) . '/' . $filepath . '/' . $image['pictureid'] . '.picture';
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'image_id' => $image['pictureid'],
|
||||
'image_album_id' => $this->db->select( 'albumid', 'albumpicture', array( "pictureid=?", $image['pictureid'] ) )->first(),
|
||||
'image_member_id' => $image['userid'],
|
||||
'image_caption' => $image['caption'],
|
||||
'image_file_name' => $image['caption'] . '.' . $image['extension'],
|
||||
'image_date' => $this->db->select( 'dateline', 'albumpicture', array( "pictureid=?", $image['pictureid'] ) )->first(),
|
||||
);
|
||||
|
||||
$libraryClass->convertGalleryImage( $info, $filepath, $filedata );
|
||||
|
||||
$libraryClass->setLastKeyValue( $image['pictureid'] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$libraryClass::setKey( 'attachmentid' );
|
||||
|
||||
foreach( $this->fetch( 'attachment', 'attachmentid', array( "contenttypeid=?", static::$imageContentType ) ) AS $image )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = $this->db->select( '*', 'filedata', array( "filedataid=?", $image['filedataid'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$libraryClass->setLastKeyValue( $image['attachmentid'] );
|
||||
continue;
|
||||
}
|
||||
|
||||
$filedata = NULL;
|
||||
$filepath = NULL;
|
||||
|
||||
if ( $this->app->_session['more_info']['convertGalleryImages']['file_location'] == 'database' )
|
||||
{
|
||||
$filedata = $data['filedata'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$filepath = implode( '/', preg_split( '//', $data['userid'], -1, PREG_SPLIT_NO_EMPTY ) );
|
||||
$filepath = rtrim( $this->app->_session['more_info']['convertGalleryImages']['file_location'], '/' ) . '/' . $filepath . '/' . $data['filedataid'] . '.attach';
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'image_id' => $image['attachmentid'],
|
||||
'image_album_id' => $image['contentid'],
|
||||
'image_member_id' => $image['userid'],
|
||||
'image_caption' => $image['caption'],
|
||||
'image_file_name' => $image['filename'],
|
||||
'image_date' => $image['dateline']
|
||||
);
|
||||
|
||||
$libraryClass->convertGalleryImage( $info, $filepath, $filedata );
|
||||
|
||||
$libraryClass->setLastKeyValue( $image['attachmentid'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert gallery comments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryComments()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'commentid' );
|
||||
|
||||
foreach( $this->fetch( 'picturecomment', 'commentid' ) AS $comment )
|
||||
{
|
||||
switch( $comment['state'] )
|
||||
{
|
||||
case 'visible':
|
||||
$approved = 1;
|
||||
break;
|
||||
|
||||
case 'moderation':
|
||||
$approved = 0;
|
||||
break;
|
||||
|
||||
case 'deleted':
|
||||
$approved = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* For 3.x this is just the value stored for pictureid */
|
||||
$image_id = $comment['pictureid'];
|
||||
|
||||
/* For 4.x though, we have to get the attachmentid based on the filedataid */
|
||||
if ( static::$isLegacy === FALSE )
|
||||
{
|
||||
/* If VB tracked the attachmentid, just use it so we don't have to query */
|
||||
if( $comment['sourceattachmentid'] )
|
||||
{
|
||||
$image_id = $comment['sourceattachmentid'];
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$image_id = $this->db->select( 'attachmentid', 'attachment', array( array( 'filedataid=?', $comment['filedataid'] ) ) )->first();
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
$image_id = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$libraryClass->convertGalleryComment( array(
|
||||
'comment_id' => $comment['commentid'],
|
||||
'comment_text' => $comment['pagetext'],
|
||||
'comment_img_id' => $image_id,
|
||||
'comment_author_id' => $comment['postuserid'],
|
||||
'comment_author_name' => $comment['postusername'],
|
||||
'comment_post_date' => $comment['dateline'],
|
||||
'comment_approved' => $approved,
|
||||
) );
|
||||
|
||||
$libraryClass->setLastKeyValue( $comment['commentid'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
try
|
||||
{
|
||||
if( isset( \IPS\Request::i()->albumid ) )
|
||||
{
|
||||
$data = $this->app->getLink( \IPS\Request::i()->albumid, 'gallery_albums' );
|
||||
$item = \IPS\gallery\Album::load( $data );
|
||||
|
||||
if( $item->canView() )
|
||||
{
|
||||
return $item->url();
|
||||
}
|
||||
}
|
||||
elseif( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'album.php' ) !== FALSE AND isset( \IPS\Request::i()->pictureid ) )
|
||||
{
|
||||
$data = $this->app->getLink( \IPS\Request::i()->pictureid, 'gallery_images' );
|
||||
$item = \IPS\gallery\Image::load( $data );
|
||||
|
||||
if( $item->canView() )
|
||||
{
|
||||
return $item->url();
|
||||
}
|
||||
}
|
||||
elseif( isset( \IPS\Request::i()->userid ) )
|
||||
{
|
||||
$data = $this->app->getLink( \IPS\Request::i()->userid, array( 'members', 'core_members' ) );
|
||||
return \IPS\Member::load( $data )->url();
|
||||
}
|
||||
elseif( ( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'picture.php' ) !== FALSE AND isset( \IPS\Request::i()->pictureid ) ) OR
|
||||
( mb_strpos( $url->data[ \IPS\Http\Url::COMPONENT_PATH ], 'attachment.php' ) !== FALSE AND isset( \IPS\Request::i()->attachmentid ) ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = $this->app->getLink( \IPS\Request::i()->pictureid ?: \IPS\Request::i()->attachmentid, 'gallery_images' );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
$data = \IPS\Request::i()->pictureid ?: \IPS\Request::i()->attachmentid;
|
||||
}
|
||||
|
||||
return \IPS\File::get( 'gallery_Images', \IPS\gallery\Image::load( $data )->masked_file_name )->url;
|
||||
}
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,637 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief Converter XenForo Media Gallery 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\Gallery;
|
||||
|
||||
/* 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
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "XenForo Media Gallery";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'convertGalleryCategories' => array(
|
||||
'table' => 'xengallery_category',
|
||||
'where' => NULL
|
||||
),
|
||||
'convertGalleryAlbums' => array(
|
||||
'table' => 'xengallery_album',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertGalleryImages' => array(
|
||||
'table' => 'xengallery_media',
|
||||
'where' => NULL,
|
||||
),
|
||||
'convertGalleryComments' => array(
|
||||
'table' => 'xengallery_comment',
|
||||
'where' => NULL,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses Prefix
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function usesPrefix()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'convertGalleryAlbums',
|
||||
'convertGalleryImages'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
{
|
||||
$return = array();
|
||||
switch( $method )
|
||||
{
|
||||
case 'convertGalleryAlbums':
|
||||
$options = array();
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'gallery_categories' ), 'IPS\gallery\Category' ) AS $category )
|
||||
{
|
||||
$options[$category->_id] = $category->_title;
|
||||
}
|
||||
|
||||
$return['convertGalleryAlbums']['members_gallery_category'] = array(
|
||||
'field_class' => 'IPS\\Helpers\\Form\\Select',
|
||||
'field_default' => NULL,
|
||||
'field_required' => FALSE,
|
||||
'field_extra' => array(
|
||||
'options' => $options
|
||||
),
|
||||
'field_hint' => NULL,
|
||||
);
|
||||
break;
|
||||
case 'convertGalleryImages':
|
||||
$return['convertGalleryImages']['file_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' ); } },
|
||||
);
|
||||
$return['convertGalleryImages']['media_thumb_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_gal_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( 'convert', 'RebuildGalleryImages', array( 'app' => $this->app->app_id ), 2, array( 'app' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildItemCounts', array( 'class' => 'IPS\gallery\Image' ), 3, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Album', 'count' => 0 ), 4, array( 'class' ) );
|
||||
\IPS\Task::queue( 'core', 'RebuildContainerCounts', array( 'class' => 'IPS\gallery\Category', 'count' => 0 ), 5, array( 'class' ) );
|
||||
|
||||
/* Caches */
|
||||
\IPS\Task::queue( 'convert', 'RebuildTagCache', array( 'app' => $this->app->app_id, 'link' => 'gallery_images', 'class' => 'IPS\gallery\Image' ), 3, array( 'app', 'link', 'class' ) );
|
||||
|
||||
return array( "f_gallery_images_rebuild", "f_gallery_cat_recount", "f_gallery_album_recount", "f_gallery_image_recount", "f_image_tags_recount" );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 gallery categories
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryCategories()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'category_id' );
|
||||
|
||||
foreach( $this->fetch( 'xengallery_category', 'category_id' ) AS $row )
|
||||
{
|
||||
$libraryClass->convertGalleryCategory( array(
|
||||
'category_id' => $row['category_id'],
|
||||
'category_name' => $row['category_title'],
|
||||
'category_desc' => $row['category_description'],
|
||||
'category_parent_id' => $row['parent_category_id'],
|
||||
'category_count_imgs' => $row['category_media_count'],
|
||||
'category_position' => $row['display_order']
|
||||
) );
|
||||
|
||||
/* Follows */
|
||||
foreach( $this->db->select( '*', 'xengallery_category_watch', array( "notify_on=? AND category_id=?", 'media', $row['category_id'] ) ) AS $follow )
|
||||
{
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'gallery',
|
||||
'follow_area' => 'category',
|
||||
'follow_rel_id' => $row['category_id'],
|
||||
'follow_rel_id_type' => 'gallery_categories',
|
||||
'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
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert gallery albums
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryAlbums()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'album_id' );
|
||||
|
||||
foreach( $this->fetch( 'xengallery_album', 'album_id' ) AS $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
$perm = $this->db->select( '*', 'xengallery_album_permission', array( "album_id=? AND permission=?", $row['album_id'], 'view' ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
/* If the permission row is missing for some reason, err on the side of caution and set this album private */
|
||||
$perm = array(
|
||||
'album_id' => $row['album_id'],
|
||||
'permission' => 'view',
|
||||
'access_type' => 'private',
|
||||
'share_users' => \serialize( array() ),
|
||||
);
|
||||
}
|
||||
|
||||
$socialgroup = NULL;
|
||||
if ( $perm['access_type'] == 'shared' OR $perm['access_type'] == 'followed' )
|
||||
{
|
||||
switch( $perm['access_type'] )
|
||||
{
|
||||
/* Specific members */
|
||||
case 'shared':
|
||||
$users = \unserialize( $perm['share_users'] );
|
||||
$socialgroup['members'] = array();
|
||||
|
||||
if ( count( $users ) )
|
||||
{
|
||||
foreach( $users AS $key => $user )
|
||||
{
|
||||
$socialgroup['members'][] = $user['shared_user_id'];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Followers */
|
||||
case 'followed':
|
||||
$socialgroup['members'] = array();
|
||||
foreach( $this->db->select( 'follow_user_id', 'xf_user_follow', array( "user_id=?", $row['album_user_id'] ) ) AS $user )
|
||||
{
|
||||
$socialgroup['members'][] = $user;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch( $perm['access_type'] )
|
||||
{
|
||||
case 'private':
|
||||
case 'members': # we don't have an equivalent of "members only" but we don't want to just open everything up either, so set these private.
|
||||
$type = 2;
|
||||
break;
|
||||
|
||||
case 'public':
|
||||
$type = 1;
|
||||
break;
|
||||
|
||||
case 'followed':
|
||||
case 'shared':
|
||||
$type = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'album_id' => $row['album_id'],
|
||||
'album_owner_id' => $row['album_user_id'],
|
||||
'album_description' => $row['album_description'],
|
||||
'album_name' => $row['album_title'],
|
||||
'album_type' => $type,
|
||||
'album_count_imgs' => $row['album_media_count'],
|
||||
'album_count_comments' => $row['album_comment_count'],
|
||||
'album_rating_aggregate' => $row['album_rating_avg'],
|
||||
'album_rating_count' => $row['album_rating_count'],
|
||||
'album_rating_total' => $row['album_rating_sum'],
|
||||
);
|
||||
|
||||
$category = $this->app->_session['more_info']['convertGalleryAlbums']['members_gallery_category'];
|
||||
if ( $category == 0 )
|
||||
{
|
||||
$category = NULL;
|
||||
}
|
||||
|
||||
$libraryClass->convertGalleryAlbum( $info, $socialgroup, $category );
|
||||
|
||||
/* Follows */
|
||||
foreach( $this->db->select( '*', 'xengallery_album_watch', array( "notify_on=? AND album_id=?", 'media', $row['album_id'] ) ) AS $follow )
|
||||
{
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'gallery',
|
||||
'follow_area' => 'album',
|
||||
'follow_rel_id' => $row['album_id'],
|
||||
'follow_rel_id_type' => 'gallery_albums',
|
||||
'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['album_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert gallery images
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryImages()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'media_id' );
|
||||
|
||||
foreach( $this->fetch( 'xengallery_media', 'media_id' ) AS $row )
|
||||
{
|
||||
/* Exif */
|
||||
$exif = array();
|
||||
foreach( $this->db->select( 'exif_name, exif_value', 'xengallery_exif', array( "media_id=?", $row['media_id'] ) )->setKeyField( 'exif_name' )->setValueField( 'exif_value' ) AS $key => $value )
|
||||
{
|
||||
$exif[$key] = $value;
|
||||
}
|
||||
|
||||
/* IP Address */
|
||||
try
|
||||
{
|
||||
$ip = $this->db->select( '*', 'xf_ip', array( "ip_id=?", $row['ip_id'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$ip = '127.0.0.1';
|
||||
}
|
||||
|
||||
/* Now the fun part... we need to do different things depending on the type of item this is. */
|
||||
switch( $row['media_type'] )
|
||||
{
|
||||
/* Normal image upload */
|
||||
case 'image_upload':
|
||||
try
|
||||
{
|
||||
$file_data = $this->db->select( '*', 'xf_attachment', array( "xf_attachment.content_type=? AND xf_attachment.content_id=?", 'xengallery_media', $row['media_id'] ) )
|
||||
->join( 'xf_attachment_data', 'xf_attachment.data_id = xf_attachment_data.data_id' )
|
||||
->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
/* If the file data is missing, we can't do anything. */
|
||||
$libraryClass->setLastKeyValue( $row['media_id'] );
|
||||
continue 2;
|
||||
}
|
||||
|
||||
$group = floor( $file_data['data_id'] / 1000 );
|
||||
$path = rtrim( $this->app->_session['more_info']['convertGalleryImages']['file_location'], '/' ) . '/' . $group . '/' . $file_data['data_id'] . '-' . $file_data['file_hash'] . '.data';
|
||||
$file_name = $file_data['filename'];
|
||||
$description = $row['media_description'];
|
||||
|
||||
break;
|
||||
|
||||
/* Video Embed */
|
||||
case 'video_embed':
|
||||
$path = $this->app->_session['more_info']['convertGalleryImages']['media_thumb_location'];
|
||||
|
||||
/* We need to figure out what service we came from, and the video ID */
|
||||
preg_match( '/\[media=(.*?)\](.*?)\[\/media\]/i', $row['media_tag'], $matches );
|
||||
$service = $matches[1];
|
||||
$video_id = $matches[2];
|
||||
|
||||
$file_name = $service . '_' . $video_id . '.jpg';
|
||||
$path = rtrim( $path, '/' ) . '/' . $service . '/' . $file_name;
|
||||
|
||||
try
|
||||
{
|
||||
$em = \IPS\Text\Parser::embeddableMedia( $row['media_embed_url'] );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
{
|
||||
/* If anything went wrong, back out */
|
||||
$libraryClass->setlastKeyValue( $row['media_id'] );
|
||||
continue 2;
|
||||
}
|
||||
|
||||
$description = $em . "<br>" . $row['media_description'];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$info = array(
|
||||
'image_id' => $row['media_id'],
|
||||
'image_album_id' => $row['album_id'],
|
||||
'image_category_id' => $row['category_id'],
|
||||
'image_member_id' => $row['user_id'],
|
||||
'image_caption' => $row['media_title'],
|
||||
'image_views' => $row['media_view_count'],
|
||||
'image_comments' => $row['comment_count'],
|
||||
'image_ratings_total' => $row['rating_sum'],
|
||||
'image_ratings_count' => $row['rating_count'],
|
||||
'image_rating' => $row['rating_avg'],
|
||||
'image_date' => $row['media_date'],
|
||||
'image_updated' => $row['last_edit_date'],
|
||||
'image_last_comment' => $row['last_comment_date'],
|
||||
'image_metadata' => json_encode( $exif ),
|
||||
'image_ipaddress' => $ip,
|
||||
'image_file_name' => $file_name,
|
||||
'image_description' => $description
|
||||
);
|
||||
|
||||
$libraryClass->convertGalleryImage( $info, $path );
|
||||
|
||||
/* Warnings */
|
||||
foreach( $this->db->select( '*', 'xf_warning', array( "content_type=? AND content_id=?", 'xengallery_media', $row['media_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'],
|
||||
) );
|
||||
}
|
||||
|
||||
/* Reputation */
|
||||
$likes = \unserialize( $row['like_users'] );
|
||||
if ( is_array( $likes ) AND count( $likes ) )
|
||||
{
|
||||
foreach( $likes AS $like )
|
||||
{
|
||||
$libraryClass->convertReputation( array(
|
||||
'app' => 'gallery',
|
||||
'type' => 'image_id',
|
||||
'type_id' => $row['media_id'],
|
||||
'member_id' => $like['user_id'],
|
||||
'member_received' => $row['user_id'],
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Follows */
|
||||
foreach( $this->db->select( '*', 'xengallery_media_watch', array( "media_id=?", $row['media_id'] ) ) AS $follow )
|
||||
{
|
||||
$libraryClass->convertFollow( array(
|
||||
'follow_app' => 'gallery',
|
||||
'follow_area' => 'image',
|
||||
'follow_rel_id' => $row['media_id'],
|
||||
'follow_rel_id_type' => 'gallery_images',
|
||||
'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
|
||||
) );
|
||||
}
|
||||
|
||||
$tags = NULL;
|
||||
/* Tags 1.0.x */
|
||||
if( isset( $row['media_content_tag_cache'] ) )
|
||||
{
|
||||
$tags = \unserialize( $row['media_content_tag_cache'] );
|
||||
}
|
||||
/* Tags 1.1.x */
|
||||
elseif( isset( $row['tags'] ) )
|
||||
{
|
||||
$tags = \unserialize( $row['tags'] );
|
||||
}
|
||||
|
||||
if ( is_array( $tags ) and count( $tags ) )
|
||||
{
|
||||
foreach( $tags AS $k => $tag )
|
||||
{
|
||||
$libraryClass->convertTag( array(
|
||||
'tag_meta_app' => 'gallery',
|
||||
'tag_meta_area' => 'gallery',
|
||||
'tag_meta_parent_id' => ( $row['album_id'] ) ? $row['album_id'] : $row['category_id'],
|
||||
'tag_meta_id' => $row['media_id'],
|
||||
'tag_text' => isset( $tag['tag_clean'] ) ? $tag['tag_clean'] : $tag['tag'], // Select 1.0 or 1.1 version
|
||||
'tag_prefix' => 0,
|
||||
'tag_member_id' => $row['user_id']
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['media_id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert gallery comments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertGalleryComments()
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
$libraryClass::setKey( 'comment_id' );
|
||||
|
||||
foreach( $this->fetch( 'xengallery_comment', 'comment_id', array( "content_type=?", 'media' ) ) AS $row )
|
||||
{
|
||||
/* IP Address */
|
||||
try
|
||||
{
|
||||
$ip = $this->db->select( 'ip', 'xf_ip', array( "ip_id=?", $row['ip_id'] ) )->first();
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$ip = '127.0.0.1';
|
||||
}
|
||||
|
||||
/* Approved */
|
||||
switch( $row['comment_state'] )
|
||||
{
|
||||
case 'visible':
|
||||
$approved = 1;
|
||||
break;
|
||||
|
||||
case 'moderated':
|
||||
$approved = 0;
|
||||
break;
|
||||
|
||||
case 'deleted':
|
||||
$approved = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
$libraryClass->convertGalleryComment( array(
|
||||
'comment_id' => $row['comment_id'],
|
||||
'comment_text' => $row['message'],
|
||||
'comment_img_id' => $row['content_id'],
|
||||
'comment_author_id' => $row['user_id'],
|
||||
'comment_author_name' => $row['username'],
|
||||
'comment_ip_address' => $ip,
|
||||
'comment_post_date' => $row['comment_date'],
|
||||
'comment_approved' => $approved,
|
||||
) );
|
||||
|
||||
/* Reputation */
|
||||
$likes = \unserialize( $row['like_users'] );
|
||||
if ( is_array( $likes ) AND count( $likes ) )
|
||||
{
|
||||
foreach( $likes AS $like )
|
||||
{
|
||||
$libraryClass->convertReputation( array(
|
||||
'app' => 'gallery',
|
||||
'type' => 'comment_id',
|
||||
'type_id' => $row['comment_id'],
|
||||
'member_id' => $like['user_id'],
|
||||
'member_received' => $row['user_id'],
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Warnings */
|
||||
foreach( $this->db->select( '*', 'xf_warning', array( "content_type=? AND content_id=?", 'xengallery_comment', $row['comment_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'],
|
||||
) );
|
||||
}
|
||||
|
||||
$libraryClass->setLastKeyValue( $row['comment_id'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user