public static function execute($params)
 {
     // Set progress
     Ai1wm_Status::info(__('Retrieving a list of all WordPress files...', AI1WM_PLUGIN_NAME));
     // Set exclude filters
     $exclude_filters = ai1wm_content_filters();
     // Exclude cache
     if (isset($params['options']['no_cache'])) {
         $exclude_filters[] = 'cache';
     }
     // Exclude themes
     if (isset($params['options']['no_themes'])) {
         $exclude_filters[] = 'themes';
     } else {
         $inactive_themes = array();
         // Exclude inactive themes
         if (isset($params['options']['no_inactive_themes'])) {
             foreach (wp_get_themes() as $theme => $info) {
                 // Exclude current parent and child themes
                 if (!in_array($theme, array(get_template(), get_stylesheet()))) {
                     $inactive_themes[] = 'themes' . DIRECTORY_SEPARATOR . $theme;
                 }
             }
         }
         // Set exclude filters
         $exclude_filters = array_merge($exclude_filters, $inactive_themes);
     }
     // Exclude plugins
     if (isset($params['options']['no_plugins'])) {
         $exclude_filters = array_merge($exclude_filters, array('plugins', 'mu-plugins'));
     } else {
         $inactive_plugins = array();
         // Exclude inactive plugins
         if (isset($params['options']['no_inactive_plugins'])) {
             foreach (get_plugins() as $basename => $plugin) {
                 if (is_plugin_inactive($basename)) {
                     if (dirname($basename) === '.') {
                         $inactive_plugins[] = 'plugins' . DIRECTORY_SEPARATOR . basename($basename);
                     } else {
                         $inactive_plugins[] = 'plugins' . DIRECTORY_SEPARATOR . dirname($basename);
                     }
                 }
             }
         }
         // Set exclude filters
         $exclude_filters = array_merge($exclude_filters, ai1wm_plugin_filters($inactive_plugins));
     }
     // Exclude media
     if (isset($params['options']['no_media'])) {
         $exclude_filters = array_merge($exclude_filters, array('uploads', 'blogs.dir'));
     }
     // Get total files
     if (isset($params['total_files'])) {
         $total_files = (int) $params['total_files'];
     } else {
         $total_files = 0;
     }
     // Get total size
     if (isset($params['total_size'])) {
         $total_size = (int) $params['total_size'];
     } else {
         $total_size = 0;
     }
     // Create map file
     $filemap = fopen(ai1wm_filemap_path($params), 'a+');
     try {
         // Iterate over content directory
         $iterator = new Ai1wm_Recursive_Directory_Iterator(WP_CONTENT_DIR);
         // Exclude uploads, plugins or themes
         $iterator = new Ai1wm_Recursive_Exclude_Filter($iterator, apply_filters('ai1wm_exclude_content_from_export', $exclude_filters));
         // Recursively iterate over content directory
         $iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD);
         // Write path line
         foreach ($iterator as $item) {
             if ($item->isFile()) {
                 if (fwrite($filemap, $iterator->getSubPathName() . PHP_EOL)) {
                     $total_files++;
                     // Add current file size
                     $total_size += filesize($iterator->getPathname());
                 }
             }
         }
     } catch (Exception $e) {
         // Skip bad file permissions
     }
     // Set total files
     $params['total_files'] = $total_files;
     // Set total size
     $params['total_size'] = $total_size;
     // Close the filemap file
     fclose($filemap);
     // Set progress
     Ai1wm_Status::info(__('Done retrieving a list of all WordPress files.', AI1WM_PLUGIN_NAME));
     return $params;
 }
	public static function execute( $params ) {

		// Set content offset
		if ( isset( $params['content_offset'] ) ) {
			$content_offset = (int) $params['content_offset'];
		} else {
			$content_offset = 0;
		}
		// Set filemap offset
		if ( isset( $params['filemap_offset'] ) ) {
			$filemap_offset = (int) $params['filemap_offset'];
		} else {
			$filemap_offset = 0;
		}

		// Get total files
		if ( isset( $params['total_files'] ) ) {
			$total_files = (int) $params['total_files'];
		} else {
			$total_files = 1;
		}

		// Get total size
		if ( isset( $params['total_size'] ) ) {
			$total_size = (int) $params['total_size'];
		} else {
			$total_size = 1;
		}

		// Get processed files
		if ( isset( $params['processed'] ) ) {
			$processed = (int) $params['processed'];
		} else {
			$processed = 0;
		}

		// What percent of files have we processed?
		$progress = (int) ( ( $processed / $total_size ) * 100 );

		// Set progress
		if ( empty( $content_offset ) ) {
			Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );
		}

		// Get map file
		$filemap = fopen( ai1wm_filemap_path( $params ), 'r' );

		// Start time
		$start = microtime( true );

		// Flag to hold if all files have been processed
		$completed = true;

		// Set filemap pointer at the current index
		if ( fseek( $filemap, $filemap_offset ) !== -1 ) {

			// Get archive
			$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );

			while ( $path = trim( fgets( $filemap ) ) ) {
				try {

					// Add file to archive
					if ( ( $content_offset = $archive->add_file( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $path, $path, $content_offset, 10 ) ) ) {

						// Set progress
						if ( ( $processed += $content_offset ) ) {
							$progress = (int) ( ( $processed / $total_size ) * 100 );
						}

						// Set progress
						Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );

						// Set content offset
						$params['content_offset'] = $content_offset;

						// Set filemap offset
						$params['filemap_offset'] = $filemap_offset;

						// Set completed flag
						$params['completed'] = false;

						// Close the filemap file
						fclose( $filemap );

						return $params;
					}

					// Set content offset
					$content_offset = 0;

					// Set filemap offset
					$filemap_offset = ftell( $filemap );

				} catch ( Exception $e ) {
					// Skip bad file permissions
				}

				// Increment processed files
				$processed += $archive->get_current_filesize();

				// More than 10 seconds have passed, break and do another request
				if ( ( microtime( true ) - $start ) > 10 ) {
					$completed = false;
					break;
				}
			}

			$archive->close();
		}

		// Set content offset
		$params['content_offset'] = $content_offset;

		// Set filemap offset
		$params['filemap_offset'] = $filemap_offset;

		// Set processed files
		$params['processed'] = $processed;

		// Set completed flag
		$params['completed'] = $completed;

		// Close the filemap file
		fclose( $filemap );

		return $params;
	}
	public static function execute( $params ) {

		// Set progress
		Ai1wm_Status::info( __( 'Retrieving a list of all WordPress files...', AI1WM_PLUGIN_NAME ) );

		// Set exclude filters
		$exclude_filters = ai1wm_content_filters();

		// Exclude themes
		if ( isset( $params['options']['no_themes'] ) ) {
			$exclude_filters[] = 'themes';
		}

		// Exclude plugins
		if ( isset( $params['options']['no_plugins'] ) ) {
			$exclude_filters = array_merge( $exclude_filters, array( 'plugins', 'mu-plugins' ) );
		} else {
			$exclude_filters = array_merge( $exclude_filters, ai1wm_plugin_filters() );
		}

		// Exclude media
		if ( isset( $params['options']['no_media'] ) ) {
			$exclude_filters[] = 'uploads';
		}

		// Get total files
		if ( isset( $params['total_files'] ) ) {
			$total_files = (int) $params['total_files'];
		} else {
			$total_files = 0;
		}

		// Get total size
		if ( isset( $params['total_size'] ) ) {
			$total_size = (int) $params['total_size'];
		} else {
			$total_size = 0;
		}

		// Create map file
		$filemap = fopen( ai1wm_filemap_path( $params ) , 'a+' );

		try {

			// Iterate over content directory
			$iterator = new Ai1wm_Recursive_Directory_Iterator( WP_CONTENT_DIR );

			// Exclude uploads, plugins or themes
			$iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, $exclude_filters );

			// Recursively iterate over content directory
			$iterator = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD );

			// Write path line
			foreach ( $iterator as $item ) {
				if ( $item->isFile() ) {
					if ( fwrite( $filemap, $iterator->getSubPathName() . PHP_EOL ) ) {
						$total_files++;

						// Add current file size
						$total_size += filesize( $iterator->getPathname() );
					}
				}
			}

		} catch ( Exception $e ) {
			// Skip bad file permissions
		}

		// Set total files
		$params['total_files'] = $total_files;

		// Set total size
		$params['total_size'] = $total_size;

		// Close the filemap file
		fclose( $filemap );

		// Set progress
		Ai1wm_Status::info( __( 'Done retrieving a list of all WordPress files.', AI1WM_PLUGIN_NAME ) );

		return $params;
	}