Version 5.0.0 beta 4
This commit is contained in:
1 parent
e86153356a
commit
2f24f9de48
276 files changed
+8614
-6044
No files matched your search
@@ -14,11 +14,15 @@ namespace IPS\convert\Software\Cms;
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use DomainException;
|
||||
use DOMXPath;
|
||||
use IPS\convert\Software;
|
||||
use IPS\convert\Software\Exception;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Task;
|
||||
use IPS\Text\DOMParser;
|
||||
use IPS\Xml\DOMDocument;
|
||||
use OutOfRangeException;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
@@ -30,16 +34,16 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
}
|
||||
|
||||
/**
|
||||
* Wordpress Pages Converter
|
||||
* WordPress Pages Converter
|
||||
*/
|
||||
class Wordpress extends Software
|
||||
{
|
||||
/**
|
||||
* Software Name
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareName()
|
||||
public static function softwareName(): string
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "WordPress (5.x)";
|
||||
@@ -48,9 +52,9 @@ class Wordpress extends Software
|
||||
/**
|
||||
* Software Key
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public static function softwareKey()
|
||||
public static function softwareKey(): string
|
||||
{
|
||||
/* Child classes must override this method */
|
||||
return "wordpress";
|
||||
@@ -59,9 +63,9 @@ class Wordpress extends Software
|
||||
/**
|
||||
* Content we can convert from this software.
|
||||
*
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public static function canConvert()
|
||||
public static function canConvert(): ?array
|
||||
{
|
||||
return array(
|
||||
'convertCmsPages' => array(
|
||||
@@ -94,32 +98,30 @@ class Wordpress extends Software
|
||||
/**
|
||||
* 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
|
||||
* @param string $table The table containing the rows to count.
|
||||
* @param string|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 )
|
||||
public function countRows( string $table, string|array|null $where=NULL, bool $recache=FALSE ): int
|
||||
{
|
||||
switch( $table )
|
||||
{
|
||||
case 'cms_database':
|
||||
return 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
return parent::countRows( $table, $where, $recache );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires Parent?
|
||||
*
|
||||
* @return bool
|
||||
* @return bool
|
||||
*/
|
||||
public static function requiresParent()
|
||||
public static function requiresParent(): bool
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -127,9 +129,9 @@ class Wordpress extends Software
|
||||
/**
|
||||
* Available Parents
|
||||
*
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public static function parents()
|
||||
public static function parents(): ?array
|
||||
{
|
||||
return array( 'core' => array( 'wordpress', 'wpforo' ) );
|
||||
}
|
||||
@@ -137,9 +139,9 @@ class Wordpress extends Software
|
||||
/**
|
||||
* List of conversion methods that require additional information
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
public static function checkConf()
|
||||
public static function checkConf(): array
|
||||
{
|
||||
return array(
|
||||
'convertAttachments',
|
||||
@@ -150,10 +152,10 @@ class Wordpress extends Software
|
||||
/**
|
||||
* Get More Information
|
||||
*
|
||||
* @param string $method Conversion method
|
||||
* @return array
|
||||
* @param string $method Conversion method
|
||||
* @return array|null
|
||||
*/
|
||||
public function getMoreInfo( $method )
|
||||
public function getMoreInfo( string $method ): ?array
|
||||
{
|
||||
$return = array();
|
||||
|
||||
@@ -188,9 +190,9 @@ class Wordpress extends Software
|
||||
/**
|
||||
* Finish - Adds everything it needs to the queues and clears data store
|
||||
*
|
||||
* @return array Messages to display
|
||||
* @return array Messages to display
|
||||
*/
|
||||
public function finish()
|
||||
public function finish(): array
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -215,7 +217,7 @@ class Wordpress extends Software
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsPages()
|
||||
public function convertCmsPages() : void
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
@@ -239,7 +241,7 @@ class Wordpress extends Software
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabases()
|
||||
public function convertCmsDatabases() : void
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
@@ -283,7 +285,7 @@ class Wordpress extends Software
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseCategories()
|
||||
public function convertCmsDatabaseCategories() : void
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
@@ -309,7 +311,7 @@ class Wordpress extends Software
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseRecords()
|
||||
public function convertCmsDatabaseRecords() : void
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
@@ -435,7 +437,7 @@ class Wordpress extends Software
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertCmsDatabaseComments()
|
||||
public function convertCmsDatabaseComments() : void
|
||||
{
|
||||
$libraryClass = $this->getLibrary();
|
||||
|
||||
@@ -475,14 +477,14 @@ class Wordpress extends Software
|
||||
}
|
||||
}
|
||||
|
||||
protected $postContent = [];
|
||||
protected array $postContent = [];
|
||||
|
||||
/**
|
||||
* Convert attachments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function convertAttachments()
|
||||
public function convertAttachments() : void
|
||||
{
|
||||
$database = $this->app->getLink( 1, 'cms_databases' );
|
||||
$contentField = $this->app->getLink( 2, 'cms_database_fields' );
|
||||
@@ -499,7 +501,7 @@ class Wordpress extends Software
|
||||
$libraryClass->setLastKeyValue( $row['ID'] );
|
||||
continue;
|
||||
}
|
||||
catch( \UnderflowException $e ) {}
|
||||
catch( UnderflowException $e ) {}
|
||||
|
||||
try
|
||||
{
|
||||
@@ -507,10 +509,10 @@ class Wordpress extends Software
|
||||
$postId = $this->app->getLink( $wpPost['ID'], "cms_custom_database_" . $database );
|
||||
if( !isset( $this->postContent[ $postId ] ) )
|
||||
{
|
||||
$this->postContent[ $postId ] = \IPS\Db::i()->select( 'field_' . $contentField, 'cms_custom_database_' . $database, array( "primary_id_field=?", $postId ) )->first();
|
||||
$this->postContent[ $postId ] = Db::i()->select( 'field_' . $contentField, 'cms_custom_database_' . $database, array( "primary_id_field=?", $postId ) )->first();
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException | \OutOfRangeException $e )
|
||||
catch( UnderflowException|OutOfRangeException $e )
|
||||
{
|
||||
$libraryClass->setLastKeyValue( $row['ID'] );
|
||||
continue;
|
||||
@@ -541,9 +543,9 @@ class Wordpress extends Software
|
||||
|
||||
if( $attachId !== FALSE AND mb_stristr( $this->postContent[ $postId ], $meta['_wp_attached_file'] ) )
|
||||
{
|
||||
$dom = new \IPS\Xml\DOMDocument( '1.0', 'UTF-8' );
|
||||
$dom->loadHTML( \IPS\Xml\DOMDocument::wrapHtml( $this->postContent[ $postId ] ) );
|
||||
$xPath = new \DOMXPath( $dom );
|
||||
$dom = new DOMDocument( '1.0', 'UTF-8' );
|
||||
$dom->loadHTML( DOMDocument::wrapHtml( $this->postContent[ $postId ] ) );
|
||||
$xPath = new DOMXPath( $dom );
|
||||
|
||||
foreach ( $xPath->query( "//img[contains(@src, '" . $meta['_wp_attached_file'] ."')] | //a[contains(@href, '" . $meta['_wp_attached_file'] ."')]" ) as $tag )
|
||||
{
|
||||
@@ -552,7 +554,7 @@ class Wordpress extends Software
|
||||
}
|
||||
|
||||
/* Get DOMDocument output */
|
||||
$content = \IPS\Text\DOMParser::getDocumentBodyContents( $dom );
|
||||
$content = DOMParser::getDocumentBodyContents( $dom );
|
||||
|
||||
/* Replace file storage tags */
|
||||
$content = preg_replace( '/<fileStore\.([\d\w\_]+?)>/i', '<fileStore.$1>', $content );
|
||||
@@ -567,7 +569,7 @@ class Wordpress extends Software
|
||||
/* Do the updates */
|
||||
foreach( $this->postContent as $pid => $content )
|
||||
{
|
||||
\IPS\Db::i()->update( 'cms_custom_database_' . $database, array( 'field_' . $contentField => $content ), array( 'primary_id_field=?', $pid ) );
|
||||
Db::i()->update( 'cms_custom_database_' . $database, array( 'field_' . $contentField => $content ), array( 'primary_id_field=?', $pid ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user