are_themes_available() ) { return FALSE; } if ( get_option( 'ai1ec_themes_version', 1 ) >= AI1EC_THEMES_VERSION ) { return FALSE; } return TRUE; } /** * copy_directory function * * @return void **/ private function copy_directory( $source, $destination ) { if( is_dir( $source ) ) { @mkdir( $destination ); $directory = dir( $source ); while( FALSE !== ( $readdirectory = $directory->read() ) ) { if( $readdirectory == '.' || $readdirectory == '..' ) { continue; } $PathDir = $source . '/' . $readdirectory; if( is_dir( $PathDir ) ) { $this->copy_directory( $PathDir, $destination . '/' . $readdirectory ); continue; } copy( $PathDir, $destination . '/' . $readdirectory ); } $directory->close(); } else { copy( $source, $destination ); } } /** * install_themes function * * @return void **/ function install_themes() { ?>

wp_content_dir() . AI1EC_THEMES_FOLDER; $result = $wp_filesystem->mkdir( $themes_root ); if( $result === false ) { ?>

wp_plugins_dir() . AI1EC_PLUGIN_NAME . DIRECTORY_SEPARATOR . AI1EC_THEMES_FOLDER; $result = copy_dir( $plugin_themes_dir, $themes_root ); if( is_wp_error( $result ) ) { ?>

.

get_error_message() ), AI1EC_PLUGIN_NAME ) ?>

.

0 || count( $files_to_delete ) > 0 || count( $folders ) > 0 || count( $folders_to_delete ) > 0 || count( $folders_to_make ) > 0 ) { // WP_Filesystem figures it out by itself, but the filesystem method may be overriden here $method = ''; $url = wp_nonce_url( AI1EC_UPDATE_THEMES_BASE_URL, AI1EC_PLUGIN_NAME . '-theme-updater' ); if( false === ( $creds = request_filesystem_credentials( $url, $method, false, false ) ) ) { // if we get here, then we don't have credentials yet, // but have just produced a form for the user to fill in, // so stop processing for now return false; // stop the normal page form from displaying } // now we have some credentials, try to get the wp_filesystem running if( ! WP_Filesystem( $creds ) ) { // our credentials were no good, ask the user for them again request_filesystem_credentials( $url, $method, true, false ); return false; } global $wp_filesystem; // 1. Create new folders foreach ( $folders_to_make as $folder_to_make ) { // try to create the folder if( FALSE === $wp_filesystem->mkdir( $dest_dir . $folder_to_make ) ) { // we were not able to create the folder, notify the user $errors[] = sprintf( __( '

There was an error creating one of the theme folders. Please FTP to your web server and manually create

%s

', AI1EC_PLUGIN_NAME ), $dest_dir . $folder_to_make ); } } // 2. Copy folders foreach ( $folders as $folder ) { // try to copy the folder $result = copy_dir( $src_dir . $folder, $dest_dir . $folder ); if( is_wp_error( $result ) ) { // we were not able to copy the folder, notify the user $errors[] = sprintf( __( '

There was an error("%s") while copying theme folders. Please FTP to your web server and manually copy

%s
to
%s

', AI1EC_PLUGIN_NAME ), $result->get_error_message(), $src_dir . $folder, $dest_dir . $folder ); } } // 3. Copy files // loop over files foreach ( $files as $file ) { // copy only files that exist if( $wp_filesystem->exists( $src_dir . $file ) ) { // was file copied successfully? if ( ! $wp_filesystem->copy( $src_dir . $file, $dest_dir . $file, true, FS_CHMOD_FILE ) ) { // If copy failed, chmod file to 0644 and try again. $wp_filesystem->chmod( $dest_dir . $file, 0644); if ( ! $wp_filesystem->copy( $src_dir . $file, $dest_dir . $file, true, FS_CHMOD_FILE ) ) { // we were not able to copy the file, notify the user $errors[] = sprintf( __( '

There was an error updating one of the files. Please FTP to your web server and manually copy

%s
to
%s

', AI1EC_PLUGIN_NAME ), $src_dir . $file, $dest_dir . $file ); } } } } // 4. Remove folders foreach ( $folders_to_delete as $folder_to_delete ) { // check if folder exist if( $wp_filesystem->is_dir( $dest_dir . $folder_to_delete ) ) { // folder actions are always recursive $recursive = true; // try to delete the folder if( FALSE === $wp_filesystem->delete( $dest_dir . $folder_to_delete, $recursive ) ) { // If delete failed, chmod folder recursively to 0644 and try again. $wp_filesystem->chmod( $dest_dir . $folder_to_delete, 0644, $recursive ); if( FALSE === $wp_filesystem->delete( $dest_dir . $folder_to_delete, $recursive ) ) { // we were not able to remove the folder, notify the user $errors[] = sprintf( __( '

There was an error deleting one of the folders. Please FTP to your web server and manually delete

%s

', AI1EC_PLUGIN_NAME ), $dest_dir . $folder_to_delete ); } } } } // 5. Remove files foreach ( $files_to_delete as $file ) { // check if file exist if( $wp_filesystem->exists( $dest_dir . $file ) ) { // try to delete the file if( FALSE === $wp_filesystem->delete( $dest_dir . $file ) ) { // If delete failed, chmod file to 0644 and try again. $wp_filesystem->chmod( $dest_dir . $file, 0644 ); if( FALSE === $wp_filesystem->delete( $dest_dir . $file ) ) { // we were not able to remove the file, notify the user $errors[] = sprintf( __( '

There was an error deleting one of the files. Please FTP to your web server and manually delete

%s

', AI1EC_PLUGIN_NAME ), $dest_dir . $file ); } } } } } // TODO: Only update the theme version when the update was successful. // Otherwise provide a way for the user to review the error log that this // update generated and to run the update again, after fixing the reported // errors. // Update theme version update_option( 'ai1ec_themes_version', AI1EC_THEMES_VERSION ); if ( $errors ) { $msg = __( '

Errors occurred while we tried to update your core calendar files.

Please follow any instructions listed below or your calendar may malfunction:

', AI1EC_PLUGIN_NAME ); } else { $msg = __( '

Your core calendar files were updated successfully.

', AI1EC_PLUGIN_NAME ); } $args = array( 'msg' => $msg, 'errors' => $errors, ); $ai1ec_view_helper->display_admin( 'themes-updated.php', $args ); } /** * Called immediately after WP theme's functions.php is loaded. Load our own * theme's functions.php at this time, and the default theme's functions.php. */ function setup_theme() { $functions_files = array( $this->active_template_path() . '/functions.php', AI1EC_DEFAULT_THEME_PATH . '/functions.php', ); $functions_files = array_unique( $functions_files ); foreach( $functions_files as $file ) { if ( file_exists( $file ) ) { include( $file ); } } } } // END class