Last active
October 21, 2020 19:22
-
-
Save karser/2b007b5937fd87e40b9b7760d4e89458 to your computer and use it in GitHub Desktop.
Here is a fix for Thrive Architect which allows to import themes from thelandingfactory when attachments are stored on S3. https://docs.thelandingfactory.com/article/51-how-do-i-install-the-template-on-my-website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// wp-content/themes/thrive-theme/inc/classes/transfer/class-thrive-transfer-import.php | |
class Thrive_Transfer_Import { | |
public function open_archive() { | |
$this->zip = new ZipArchive(); | |
$file = $this->getLocalPath($this->archive_file); // <----------------- line added | |
if ( $this->zip->open( $file ) !== true ) { | |
} | |
/** | |
* Download the file to the tmp folder if it's stored remotely. | |
* The use case is humanmade/S3-Uploads plugin. | |
* | |
* @param $file | |
* @return string | |
* @throws Exception | |
*/ | |
private function getLocalPath($file) | |
{ | |
if (strpos($file, '//') !== false) { | |
if (!$temp = tempnam(sys_get_temp_dir(), basename($file))) { | |
throw new Exception( __( 'Unable to create tmp file in '.sys_get_temp_dir(), 'thrive-cb' ) ); | |
} | |
if (!copy($file, $temp)) { | |
throw new Exception( __( 'Unable to download the archive file from '.$file, 'thrive-cb' ) ); | |
} | |
return $temp; | |
} | |
return $file; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//wp-content/plugins/thrive-visual-editor/landing-page/inc/TCB_Landing_Page_Transfer.php | |
class TCB_Landing_Page_Cloud_Templates_Api { | |
public function import( $file, $page_id ) { | |
$template_name = $this->importValidateFile( $file ); | |
$file = $this->getLocalPath($file); // <----------------- line added | |
$zip = new ZipArchive(); | |
if ( $zip->open( $file ) !== true ) { | |
throw new Exception( __( 'Could not open the archive file', 'thrive-cb' ) ); | |
} | |
/** | |
* Download the file to the tmp folder if it's stored remotely. | |
* The use case is humanmade/S3-Uploads plugin. | |
* | |
* @param $file | |
* @return string | |
* @throws Exception | |
*/ | |
private function getLocalPath($file) | |
{ | |
if (strpos($file, '//') !== false) { | |
if (!$temp = tempnam(sys_get_temp_dir(), basename($file))) { | |
throw new Exception( __( 'Unable to create tmp file in '.sys_get_temp_dir(), 'thrive-cb' ) ); | |
} | |
if (!copy($file, $temp)) { | |
throw new Exception( __( 'Unable to download the archive file from '.$file, 'thrive-cb' ) ); | |
} | |
return $temp; | |
} | |
return $file; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment