get_action_keys() as $key ) { $key_underscore = self::_key( $key ); add_action( 'wp_ajax_' . $this->action_string( $key ), array( $this, 'action_' . $key_underscore ) ); } } /** * Create or get nonce * * @param string $action The action for the nonce. * @param string $key The key to create the nonce string from. */ protected function nonce_array( $action, $key ) { if ( ! isset( $this->nonce_arrays[ $action ] ) ) { $this->nonce_arrays[ $action ] = $this->nonce( $action, $key ); } return $this->nonce_arrays[ $action ]; } /** * Enqueue scripts * * @return void */ public function admin_enqueue_scripts() { if ( $this->is_screen( $this->admin_menu_hooks_dt ) ) { wp_enqueue_script( 'jquery' ); $handle = Util::ns( 'dt-impexp' ); wp_register_script( $handle, AdCommanderTools::assets_url() . 'js/importexport.js', array( 'jquery', ), AdCommanderTools::version(), array( 'in_footer' => true ) ); wp_enqueue_script( $handle ); Util::enqueue_script_data( $handle, array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'actions' => $this->get_ajax_actions(), ) ); } } /** * Get necessary action keys, which will be used to create wp_ajax hooks. * * @return array */ private function get_action_keys() { return array( 'delete-bundle', ); } /** * Creates an array of all of the necessary actions. * * @return array */ private function get_ajax_actions() { $actions = array(); foreach ( $this->get_action_keys() as $key ) { $actions[ self::_key( $key ) ] = array( 'action' => $this->action_string( $key ), 'security' => wp_create_nonce( $this->nonce_string( $key ) ), ); } return $actions; } /** * Delete a bundle * * @return void */ public function action_delete_bundle() { $action = 'delete-bundle'; check_ajax_referer( $this->nonce_string( $action ), 'security' ); if ( ! current_user_can( AdCommander::capability() ) ) { wp_die(); } $file = isset( $_REQUEST['file'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['file'] ) ) : false; if ( Export::instance()->delete_bundle( $file ) ) { wp_send_json_success( array( 'action' => $action, ) ); } wp_die(); } /** * Enqueue styles if we're on a screen that needs them. * * @return void */ public function admin_print_styles() { if ( $this->is_screen( $this->admin_menu_hooks_dt ) ) { wp_enqueue_style( Util::ns( 'dt-tools' ), AdCommanderTools::assets_url() . 'css/admin.css', array(), AdCommanderTools::version() ); } } /** * The admin_url for the tools page. * * @return string */ public static function tools_admin_url() { return admin_url( self::admin_path( 'tools' ) ); } /** * The title of the Tools page * * @return string */ public function tools_title() { return __( 'Tools', 'ad-commander-tools' ); } /** * Create admin menu. * * @return void */ public function create_admin_menu() { $hook = add_submenu_page( self::admin_slug(), self::tools_title(), self::tools_title(), AdCommander::capability(), self::admin_slug( 'tools' ), array( $this, 'tools_page' ), 25 ); $this->admin_menu_hooks_dt[] = $hook; } /** * Filter Ad Commander menu hooks and add this plugin. * * @param array $hooks The current hooks. * * @return array */ public function admin_menu_hooks( $hooks ) { if ( is_array( $hooks ) && ! empty( $this->admin_menu_hooks_dt ) ) { $hooks = array_merge( $hooks, $this->admin_menu_hooks_dt ); } return $hooks; } /** * The tools page. * * @return void */ public function tools_page() { $this->sf()->start(); $this->sf()->title( __( 'Tools', 'ad-commander-tools' ) ); $tabs = array(); $tools['import'] = __( 'Import', 'ad-commander-tools' ); $tools['export'] = __( 'Export', 'ad-commander-tools' ); $tools['delete_stats'] = __( 'Delete Ad Stats', 'ad-commander-tools' ); $tools['debug'] = __( 'Debug', 'ad-commander-tools' ); $admin_url = self::tools_admin_url(); foreach ( $tools as $key => $text ) { $opt_key = $this->sf()->key( $key ); $tabs[] = array( 'key' => $opt_key, 'text' => esc_html( $text ), 'url' => $this->sf()->get_tab_url( $opt_key, $admin_url ), ); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification isn't needed for admin page added via add_submenu_page and processing no action. $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : $tabs[0]['key']; $this->sf()->display_tabs( $tabs, $active_tab ); foreach ( $tabs as $tab ) { if ( $active_tab !== $tab['key'] ) { continue; } switch ( $tab['key'] ) { case 'adcmdr_export': $this->export_page(); break; case 'adcmdr_import': $this->import_page(); break; case 'adcmdr_delete_stats': $this->delete_stats_page(); break; case 'adcmdr_debug': $this->debug_page(); break; } } // Close .woforms-form-inner div from display_tabs(). ?> sf()->end(); } /** * Start a form tag. * * @param string $method Get or post method. * @param bool $formdata Whether to accept file uploads. * * @return void */ private function form_start( $method = 'post', $formdata = false ) { $this->sf()->form_start( admin_url( 'admin.php' ), $method, $formdata ); } /** * End a form. * * @return void */ private function form_end() { ?> nonce_array( 'adcmdr-do_export', 'export' ); ?>
info( esc_html__( "Your host doesn't appear to support the necessary libraries for exporting and compressing your data. We are unable to create export bundles at this time.", 'ad-commander-tools' ), array( 'adcmdr-metaitem__warning' ) ); } else { $this->form_start(); ?> nonce_field( $export_nonce ); Html::admin_table_start(); ?>' . esc_html( $tmp_dir ) . '';
}
?>
' . esc_html( $extract_to_dir ) . '';
global $wp_filesystem;
$dir_info = array(
'chmod' => $wp_filesystem->getchmod( $extract_to_dir ),
'owner' => $wp_filesystem->owner( $extract_to_dir ),
'group' => $wp_filesystem->group( $extract_to_dir ),
);
echo ''; print_r( $dir_info ); echo ''; } ?>
'; print_r( $filelist ); echo ''; } ?>