Changeset 3071479
- Timestamp:
- 04/16/2024 10:18:33 AM (22 months ago)
- Location:
- ghost/trunk
- Files:
-
- 3 edited
-
class-ghost.php (modified) (9 diffs)
-
ghost.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ghost/trunk/class-ghost.php
r2995134 r3071479 26 26 * @var string 27 27 */ 28 protected $version = '1. 4.0';28 protected $version = '1.5.0'; 29 29 30 30 /** … … 62 62 protected $date_format = 'Y-m-d\TH:i:sP'; 63 63 protected $ghost_image_base = 'content/images/wordpress'; 64 protected $json_file_name = 'wp_ghost_export.json'; 65 protected $zip_file_name = 'wp_ghost_export.zip'; 64 66 65 67 /** … … 78 80 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) ); 79 81 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); 82 83 // Init deleting if old exports 84 add_action( 'init', array( $this, 'deleteLocalExportFiles' ) ); 80 85 81 86 if ( isset( $_GET['ghostexport'] ) ) { … … 144 149 public static function deactivate( $network_wide ) { 145 150 // TODO: Define deactivation functionality here 151 } 152 153 /** 154 * Deleted locally saved export files, which prior versions saved in the uploads directory. 155 * 156 * @since 1.5.0 157 */ 158 function deleteLocalExportFiles() { 159 // Get the files in the directory, ignoring the . and .. 160 $upload_dir = wp_upload_dir(); 161 $gfiledir = $upload_dir['basedir'] . '/ghost-exports'; 162 163 // Return if directory does not exist 164 if ( ! is_dir($gfiledir) ) { 165 return; 166 } 167 168 $filesInDir = scandir($gfiledir); 169 $slicesFilesInDir = array_slice($filesInDir); 170 171 // Delete each file 172 foreach ($slicesFilesInDir as $file) { 173 unlink($gfiledir . '/' . $file); 174 } 175 176 // And delete the directory 177 rmdir($gfiledir); 146 178 } 147 179 … … 600 632 $upload_dir = wp_upload_dir(); 601 633 $filedir = $upload_dir['basedir']; 602 $gfiledir = $upload_dir['basedir'] . '/ghost-exports'; 603 if ( ! file_exists( $gfiledir ) ) { 604 wp_mkdir_p( $gfiledir ); 605 } 606 $filename = 'wp_ghost_export.json'; 607 608 if ( ! is_writable( $gfiledir ) ) { 609 wp_die( "<p>Uploads directory is not writable, can't save the Ghost json file :/</p><p>Generated by the Ghost plugin version {$this->version}.</p>", 'Directory not writable' ); 610 } 611 612 $handle = fopen( $gfiledir . '/' . $filename, 'w' ); 634 613 635 $content = $this->get_json( $this->garray ); 614 636 615 637 // Remove extra backslashes and quotes added due to double encoding and replace WordPress uploads URL with Ghost relative URL. 616 638 $cleaned_content = $this->clean_content_json($content); 617 618 fwrite( $handle, $cleaned_content );619 fclose( $handle );620 621 // Generate a zip archive of images in a Ghost compatible directory structure as well as the JSON file.622 639 623 640 // Ensure ZipArchive is installed. … … 627 644 628 645 // Initialise the archive object 629 $gziparchivename = 'wp_ghost_export.zip';630 646 $gziparchive = new ZipArchive(); 631 $gziparchive->open( $gfiledir . '/' . $gziparchivename, ZipArchive::CREATE | ZipArchive::OVERWRITE ); 647 648 $tmp_file = tmpfile(); 649 $tmp_location = stream_get_meta_data($tmp_file)['uri']; 650 651 $res = $gziparchive->open($tmp_location, ZipArchive::CREATE); 632 652 633 653 // Create recursive directory iterator … … 639 659 640 660 // Set which files to exclude from being zipped. 641 $gexclusions = array( $gziparchivename);661 $gexclusions = array( $this->zip_file_name ); 642 662 // Set which extensions to include. 643 $gincludedextensions = array( "jpg", "jpeg", "gif", "png", "svg", "svgz", "ico");663 $gincludedextensions = array( 'jpg', 'jpeg', 'gif', 'png', 'svg', 'svgz', 'ico', 'webp' ); 644 664 645 665 foreach ( $files as $name => $file ) { … … 653 673 // Add current file to archive in dedicated WordPress folder within a Ghost compatible directory structure. 654 674 $gziparchive->addFile( $filePath, $this->ghost_image_base . '/' . $relativePath ); 655 } elseif ( $file->getFilename() == $filename ) {656 // Get real and relative path for current file657 $filePath = $file->getRealPath();658 $relativePath = substr( $filePath, strlen($gfiledir) + 1 );659 // Add current file to archive in dedicated WordPress folder within a Ghost compatible directory structure.660 $gziparchive->addFile( $filePath, 'json/' . $relativePath );661 675 } 662 676 } 663 677 664 // Zip archive will be created only after closing object 678 $gziparchive->addFromString( 'json/' . $this->json_file_name, $cleaned_content ); 679 665 680 $gziparchive->close(); 666 681 667 header( 'Content-Description: File Transfer' ); 668 header( 'Content-Type: application/octet-stream' ); 669 header( 'Content-Disposition: attachment; filename=' . $gziparchivename ); 670 header( 'Content-Transfer-Encoding: binary' ); 671 header( 'Expires: 0' ); 672 header( 'Cache-Control: must-revalidate' ); 673 header( 'Pragma: public' ); 674 header( 'Content-Length: ' . filesize( $gfiledir . '/' . $gziparchivename ) ); 675 676 flush(); 677 678 readfile( $gfiledir . '/' . $gziparchivename ); 682 header( 'Content-type: application/octet-stream' ); 683 header( 'Content-Disposition: attachment; filename=' . $this->zip_file_name ); 684 685 echo( readfile( $tmp_location ) ); 686 679 687 exit; 680 688 } … … 692 700 $this->populate_data(); 693 701 694 $upload_dir = wp_upload_dir();695 $filedir = $upload_dir['basedir'];696 $gfiledir = $upload_dir['basedir'] . '/ghost-exports';697 if ( ! file_exists( $gfiledir ) ) {698 wp_mkdir_p( $gfiledir );699 }700 $filename = 'wp_ghost_export.json';701 702 if ( ! is_writable( $gfiledir ) ) {703 wp_die( "<p>Uploads directory is not writable, can't save the Ghost json file :/</p><p>Generated by the Ghost plugin version {$this->version}.</p>", 'Directory not writable' );704 }705 706 $handle = fopen( $gfiledir . '/' . $filename, 'w' );707 702 $content = $this->get_json( $this->garray ); 708 703 709 704 // Remove extra backslashes and quotes added due to double encoding and replace WordPress uploads URL with Ghost relative URL. 710 $cleaned_content = $this->clean_content_json($content); 711 712 fwrite( $handle, $cleaned_content ); 713 fclose( $handle ); 714 715 header( 'Content-Description: File Transfer' ); 716 header( 'Content-Type: application/octet-stream' ); 717 header( 'Content-Disposition: attachment; filename='.$filename ); 718 header( 'Content-Transfer-Encoding: binary' ); 719 header( 'Expires: 0' ); 720 header( 'Cache-Control: must-revalidate' ); 721 header( 'Pragma: public' ); 722 header( 'Content-Length: ' . filesize( $gfiledir . '/' . $filename ) ); 723 724 flush(); 725 726 readfile( $gfiledir . '/' . $filename ); 705 $cleaned_content = $this->clean_content_json( $content ); 706 707 header ( 'Content-Type: application/octet-stream' ); 708 header ( 'Content-disposition: attachment; filename=' . $this->json_file_name ); 709 echo $cleaned_content; 727 710 728 711 exit; -
ghost/trunk/ghost.php
r2995134 r3071479 13 13 * Plugin URI: http://ghost.org 14 14 * Description: Plugin to export your WordPress blog so you can import it into your Ghost installation 15 * Version: 1. 4.015 * Version: 1.5.0 16 16 * Author: Ghost Foundation 17 17 * Author URI: http://ghost.org -
ghost/trunk/readme.txt
r2995134 r3071479 4 4 Tags: ghost, export, migrate, blogging, publishing 5 5 Requires at least: 4.2.0 6 Tested up to: 6. 4.17 Stable tag: 1. 4.06 Tested up to: 6.5 7 Stable tag: 1.5.0 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 61 61 62 62 == Changelog == 63 64 = 1.5.0 = 65 66 * Delete prior exports and change how new exports are generated - Credit to [Joshua Chan](https://patchstack.com/database/researcher/7d630755-51bd-4c8b-8d77-a700aea26d1d) 67 * Test & ensure compatibility with WorePress 6.5 63 68 64 69 = 1.4.0 =
Note: See TracChangeset
for help on using the changeset viewer.