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,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" );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user