'; SRPP_Admin::header( __( 'Tools', 'advanced-css3-related-posts-widget' ), __( 'Maintenance, backups and moving displays between sites.', 'advanced-css3-related-posts-widget' ), '', array( 'icon' => 'refresh' ) ); echo '
'; self::card( __( 'Recommendation cache', 'advanced-css3-related-posts-widget' ), sprintf( /* translators: %s: number of cached rows */ __( '%s cached recommendation lists are stored right now. Clearing them forces a fresh calculation on the next page view.', 'advanced-css3-related-posts-widget' ), number_format_i18n( SRPP_Cache::count_rows() ) ), 'purge_cache', __( 'Clear cache', 'advanced-css3-related-posts-widget' ), false, 'database', 'teal' ); self::card( __( 'Statistics', 'advanced-css3-related-posts-widget' ), __( 'Delete every impression and click row. This cannot be undone.', 'advanced-css3-related-posts-widget' ), 'reset_stats', __( 'Reset statistics', 'advanced-css3-related-posts-widget' ), true, 'chart', 'coral' ); echo '
'; self::export_import(); echo ''; } /** * One tool card. * * @param string $title Title. * @param string $body Copy. * @param string $action Action key. * @param string $button Button label. * @param bool $danger Danger styling. */ protected static function card( $title, $body, $action, $button, $danger = false, $icon = 'refresh', $tone = 'amber' ) { $url = wp_nonce_url( add_query_arg( array( 'page' => 'srpp-tools', 'srpp_tool' => $action ), admin_url( 'admin.php' ) ), 'srpp_tool_' . $action ); printf( '
%s

%s

%s

%s
', SRPP_Admin::tile( $icon, $tone, true ), // phpcs:ignore WordPress.Security.EscapeOutput esc_html( $title ), esc_html( $body ), $danger ? 'srpp-danger' : '', esc_url( $url ), esc_html( $button ) ); } /** * Export / import panel. */ protected static function export_import() { $export = wp_nonce_url( add_query_arg( array( 'page' => 'srpp-tools', 'srpp_tool' => 'export' ), admin_url( 'admin.php' ) ), 'srpp_tool_export' ); ?>

'srpp-tools', 'srpp_msg' => 'cache' ), admin_url( 'admin.php' ) ) ); exit; case 'reset_stats': SRPP_Analytics::reset(); wp_safe_redirect( add_query_arg( array( 'page' => 'srpp-tools', 'srpp_msg' => 'stats' ), admin_url( 'admin.php' ) ) ); exit; case 'export': self::export(); exit; } } /** * Stream a JSON export. */ protected static function export() { $out = array( 'plugin' => 'stunning-related', 'version' => SRPP_VERSION, 'items' => array(), ); foreach ( SRPP_Display::all() as $display ) { $out['items'][] = array( 'title' => $display->title, 'status' => $display->status, 'config' => $display->config, ); } nocache_headers(); header( 'Content-Type: application/json; charset=utf-8' ); header( 'Content-Disposition: attachment; filename=stunning-related-displays-' . gmdate( 'Y-m-d' ) . '.json' ); echo wp_json_encode( $out, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); } /** * Import from an uploaded JSON file. * * Only reached from self::handle(), which verifies the srpp_import nonce * and the capability before calling in. */ protected static function import() { // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput -- Nonce verified in self::handle(); value validated by is_uploaded_file() below. if ( empty( $_FILES['srpp_import_file']['tmp_name'] ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput -- Nonce verified in self::handle(); value validated by is_uploaded_file() below. $path = sanitize_text_field( $_FILES['srpp_import_file']['tmp_name'] ); if ( ! is_uploaded_file( $path ) ) { return; } $raw = file_get_contents( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions $data = json_decode( $raw, true ); if ( empty( $data['items'] ) || ! is_array( $data['items'] ) ) { return; } foreach ( $data['items'] as $item ) { if ( empty( $item['config'] ) ) { continue; } SRPP_Display::save( 0, array( 'title' => isset( $item['title'] ) ? $item['title'] : __( 'Imported display', 'advanced-css3-related-posts-widget' ), 'status' => isset( $item['status'] ) ? $item['status'] : 'draft', 'config' => $item['config'], ) ); } wp_safe_redirect( add_query_arg( array( 'page' => 'srpp-tools', 'srpp_msg' => 'imported' ), admin_url( 'admin.php' ) ) ); exit; } }