Version 4.7.23

This commit is contained in:
Neo committed 2025-12-19 16:21:27 -08:00
1 parent 7124a02564
commit 25ddeb65d6
1791 files changed
+76990 -44452

No files matched your search

@@ -73,7 +73,7 @@ class _Wordpress extends \IPS\convert\Software
'table' => 'comments',
'where' => NULL
),
'convertCmsMedia' => array(
'convertAttachments' => array(
'table' => 'posts',
'where' => array( "post_type=?", 'attachment' )
)
@@ -131,7 +131,7 @@ class _Wordpress extends \IPS\convert\Software
public static function checkConf()
{
return array(
'convertCmsMedia',
'convertAttachments',
'convertCmsDatabaseRecords'
);
}
@@ -159,8 +159,8 @@ class _Wordpress extends \IPS\convert\Software
);
break;
case 'convertCmsMedia':
$return['convertCmsMedia']['file_location'] = array(
case 'convertAttachments':
$return['convertAttachments']['file_location'] = array(
'field_class' => 'IPS\\Helpers\\Form\\Text',
'field_required' => TRUE,
'field_default' => NULL,
@@ -464,46 +464,99 @@ class _Wordpress extends \IPS\convert\Software
}
}
protected $postContent = [];
/**
* Convert CMS media
* Convert attachments
*
* @return void
*/
public function convertCmsMedia()
public function convertAttachments()
{
$database = $this->app->getLink( 1, 'cms_databases' );
$contentField = $this->app->getLink( 2, 'cms_database_fields' );
$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'];
}
/* No filename, no convert */
if( !isset( $meta['_wp_attached_file'] ) )
$data = iterator_to_array( $this->fetch( 'posts', 'ID', [ 'post_type=?', 'attachment' ] ) );
$this->app->preCacheLinks( $data, [ 'core_members' => 'post_author' ] );
foreach( $data AS $row )
{
try
{
$this->db->select( '*', 'postmeta', [ 'meta_key=? AND meta_value=?', '_thumbnail_id', $row['ID'] ] )->first();
$libraryClass->setLastKeyValue( $row['ID'] );
continue;
}
catch( \UnderflowException $e ) {}
try
{
$wpPost = $this->db->select( '*', 'posts', [ 'ID=? AND post_type=?', $row['post_parent'], 'post' ] )->first();
$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();
}
}
catch( \UnderflowException | \OutOfRangeException $e )
{
$libraryClass->setLastKeyValue( $row['ID'] );
continue;
}
$filename = explode( '/', $meta['_wp_attached_file'] );
$filename = array_pop( $filename );
$path = rtrim( $this->app->_session['more_info']['convertCmsMedia']['file_location'], '/' );
/* Post Meta */
$meta = array();
foreach( $this->db->select( '*', 'postmeta', array( "post_id=?", $row['ID'] ) ) AS $m )
{
$meta[ $m['meta_key'] ] = $m['meta_value'];
}
$map = [
'id1' => $wpPost['ID'],
'id2' => 2,
'id2_type' => 'cms_database_fields',
'id3' => 1
];
$info = array(
'media_id' => $row['ID'],
'media_filename' => $filename,
'media_added' => new \IPS\DateTime( $row['post_date'] ),
'attach_id' => $row['ID'],
'attach_file' => basename( $meta['_wp_attached_file'] ),
'attach_date' => new \IPS\DateTime( $row['post_date'] ),
'attach_member_id' => $row['post_author']
);
$libraryClass->convertCmsMedia( $info, $path . '/' . $meta['_wp_attached_file'] );
$attachId = $libraryClass->convertAttachment( $info, $map, rtrim( $this->app->_session['more_info']['convertAttachments']['file_location'], '/' ) . '/' . $meta['_wp_attached_file'] );
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 );
foreach ( $xPath->query( "//img[contains(@src, '" . $meta['_wp_attached_file'] ."')] | //a[contains(@href, '" . $meta['_wp_attached_file'] ."')]" ) as $tag )
{
$text = $dom->createTextNode( '[attachment=' . $attachId . ':name]' );
$tag->parentNode->replaceChild( $text, $tag );
}
/* Get DOMDocument output */
$content = \IPS\Text\DOMParser::getDocumentBodyContents( $dom );
/* Replace file storage tags */
$content = preg_replace( '/&lt;fileStore\.([\d\w\_]+?)&gt;/i', '<fileStore.$1>', $content );
/* DOMDocument::saveHTML will encode the base_url brackets, so we need to make sure it's in the expected format. */
$this->postContent[ $postId ] = str_replace( '&lt;___base_url___&gt;', '<___base_url___>', $content );
}
$libraryClass->setLastKeyValue( $row['ID'] );
}
/* 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 ) );
}
}
}