wp-content
mu-plugins
plugins
activitypub
authLdap-2.4.2
authldap
disable-wordpress-core-update
gitium
gp-premium
menu-icons
simple-local-avatars
static-html-output-plugin
languages
plugin
CSSParser
FTP
URL2
WP2Static
Archive.php
ArchiveProcessor.php
CSSProcessor.php
DBSettings.php
Deployer.php
Dispatcher.php
Exporter.php
FileCopier.php
FileWriter.php
FilesHelper.php
HTMLProcessor.php
MimeTypes.php
Options.php
PostSettings.php
ProgressLog.php
Request.php
SiteCrawler.php
SitePublisher.php
TXTProcessor.php
TemplateHelper.php
View.php
WP2Static.php
WPSite.php
WsLog.php
deployers
WP2Static.php
wp2static-wp-cli-commands.php
views
readme.txt
wp2static.css
wp2static.php
wp-mail-smtp
wp-piwik
index.php
themes
index.php
.dbsetup
.gitignore
htaccess
php.ini
2 lines
2.1 KiB
PHP
2 lines
2.1 KiB
PHP
<?php
|
|
class FileWriter extends WP2Static { public function __construct( $url, $content, $file_type, $content_type ) { $this->url = $url; $this->content = $content; $this->file_type = $file_type; $this->content_type = $content_type; $this->loadSettings( array( 'wpenv', ) ); } public function saveFile( $archive_dir ) { $url_info = parse_url( $this->url ); $path_info = array(); if ( ! isset( $url_info['path'] ) ) { return false; } if ( $url_info['path'] != '/' ) { $path_info = pathinfo( $url_info['path'] ); } else { $path_info = pathinfo( 'index.html' ); } $directory_in_archive = isset( $path_info['dirname'] ) ? $path_info['dirname'] : ''; if ( ! empty( $this->settings['wp_site_subdir'] ) ) { $directory_in_archive = str_replace( $this->settings['wp_site_subdir'], '', $directory_in_archive ); } $file_dir = $archive_dir . ltrim( $directory_in_archive, '/' ); if ( empty( $path_info['extension'] ) && $path_info['basename'] === $path_info['filename'] ) { $file_dir .= '/' . $path_info['basename']; $path_info['filename'] = 'index'; } if ( ! file_exists( $file_dir ) ) { wp_mkdir_p( $file_dir ); } $file_extension = ''; if ( isset( $path_info['extension'] ) ) { $file_extension = $path_info['extension']; } elseif ( $this->file_type == 'html' ) { $file_extension = 'html'; } elseif ( $this->file_type == 'xml' ) { $file_extension = 'html'; } $filename = ''; if ( $url_info['path'] == '/' ) { $filename = rtrim( $file_dir, '.' ) . 'index.html'; } else { if ( ! empty( $this->settings['wp_site_subdir'] ) ) { $file_dir = str_replace( '/' . $this->settings['wp_site_subdir'], '/', $file_dir ); } $filename = $file_dir . '/' . $path_info['filename'] . '.' . $file_extension; } $file_contents = $this->content; if ( $file_contents ) { $this->logAction( 'SAVING ' . $this->url . ' to ' . $filename ); file_put_contents( $filename, $file_contents ); chmod( $filename, 0664 ); } else { $this->logAction( 'NOT SAVING EMTPY FILE ' . $this->url ); } } public function logAction( $action ) { if ( ! isset( $this->settings['debug_mode'] ) ) { return; } require_once dirname( __FILE__ ) . '/WsLog.php'; WsLog::l( $action ); } }
|