. * * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗ * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝ * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝ * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗ * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗ * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ */ class Ai1wm_Export_Controller { public static function index() { Ai1wm_Template::render( 'export/index' ); } public static function export( $params = array() ) { global $wp_filter; // Set error handler @set_error_handler( 'Ai1wm_Handler::error' ); // Set shutdown handler @register_shutdown_function( 'Ai1wm_Handler::shutdown' ); // Set params if ( empty( $params ) ) { $params = stripslashes_deep( $_REQUEST ); } // Set priority $priority = 5; if ( isset( $params['priority'] ) ) { $priority = (int) $params['priority']; } // Set secret key $secret_key = null; if ( isset( $params['secret_key'] ) ) { $secret_key = trim( $params['secret_key'] ); } try { // Ensure that unauthorized people cannot access export action ai1wm_verify_secret_key( $secret_key ); } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) { exit; } // Get hook if ( isset( $wp_filter['ai1wm_export'] ) && ( $filters = $wp_filter['ai1wm_export'] ) ) { // WordPress 4.7 introduces new class for working with filters/actions called WP_Hook // which adds another level of abstraction and we need to address it. if ( isset( $filters->callbacks ) ) { $filters = $filters->callbacks; } ksort( $filters ); // Loop over filters while ( $hooks = current( $filters ) ) { if ( $priority === key( $filters ) ) { foreach ( $hooks as $hook ) { try { // Run function hook $params = call_user_func_array( $hook['function'], array( $params ) ); // Log request Ai1wm_Log::export( $params ); } catch ( Exception $e ) { Ai1wm_Status::error( $e->getMessage() ); Ai1wm_Directory::delete( ai1wm_storage_path( $params ) ); exit; } } // Set completed $completed = true; if ( isset( $params['completed'] ) ) { $completed = (bool) $params['completed']; } // Do request if ( $completed === false || ( $next = next( $filters ) ) && ( $params['priority'] = key( $filters ) ) ) { if ( isset( $params['ai1wm_manual_export'] ) ) { echo json_encode( $params ); exit; } return Ai1wm_Http::get( admin_url( 'admin-ajax.php?action=ai1wm_export' ), $params ); } } next( $filters ); } } } public static function buttons() { return array( apply_filters( 'ai1wm_export_file', Ai1wm_Template::get_content( 'export/button-file' ) ), apply_filters( 'ai1wm_export_ftp', Ai1wm_Template::get_content( 'export/button-ftp' ) ), apply_filters( 'ai1wm_export_dropbox', Ai1wm_Template::get_content( 'export/button-dropbox' ) ), apply_filters( 'ai1wm_export_gdrive', Ai1wm_Template::get_content( 'export/button-gdrive' ) ), apply_filters( 'ai1wm_export_s3', Ai1wm_Template::get_content( 'export/button-s3' ) ), apply_filters( 'ai1wm_export_onedrive', Ai1wm_Template::get_content( 'export/button-onedrive' ) ), apply_filters( 'ai1wm_export_box', Ai1wm_Template::get_content( 'export/button-box' ) ), ); } }