esc_html__( 'Forbidden.', 'advance-wp-redirect' ) ) ); } check_ajax_referer( 'xsawrlite_admin', 'nonce' ); } /** * Admin menu. */ public function xsawrlite_admin_menu() { add_menu_page( esc_html__( 'Advance WP Redirect', 'advance-wp-redirect' ), esc_html__( 'Advance WP Redirect', 'advance-wp-redirect' ), 'manage_options', 'xsawrlite_page', 'xsawrlite_page', 'dashicons-external', 40 ); add_submenu_page( 'xsawrlite_page', esc_html__( 'Support', 'advance-wp-redirect' ), esc_html__( 'Support', 'advance-wp-redirect' ), 'manage_options', 'xsawrlite_support', 'xsawrlite_support' ); } /** * Enqueue admin CSS/JS (no external stylesheets). */ public function xsawrlite_load_css_js() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only admin page slug. $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( 'xsawrlite_page' !== $page && 'xsawrlite_support' !== $page ) { return; } $ver = XSAWRLITE_VERSION; $url = $this->xsawrlite_assets_url(); wp_register_style( 'xsawrlite-material', $url . 'assets/css/xsawrlite.material.min.css', array(), $ver ); wp_register_style( 'xsawrlite-custom', $url . 'assets/css/xsawrlite.custom.css', array( 'xsawrlite-material' ), $ver ); wp_register_script( 'xsawrlite-material', $url . 'assets/js/xsawrlite.material.min.js', array( 'jquery' ), $ver, true ); wp_register_script( 'xsawrlite-custom', $url . 'assets/js/xsawrlite.custom.js', array( 'jquery', 'xsawrlite-material' ), $ver, true ); wp_enqueue_style( 'xsawrlite-material' ); wp_enqueue_style( 'xsawrlite-custom' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'xsawrlite-material' ); wp_enqueue_script( 'xsawrlite-custom' ); wp_localize_script( 'xsawrlite-custom', 'xsawrliteAdmin', array( 'nonce' => wp_create_nonce( 'xsawrlite_admin' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), ) ); } /** * Front-end script for link attributes. */ public function xsawrlite_forntend_load_js() { wp_enqueue_script( 'xsawrlite-frontend', $this->xsawrlite_assets_url() . 'assets/js/xsawrlite.frontend.js', array( 'jquery' ), XSAWRLITE_VERSION, true ); wp_localize_script( 'xsawrlite-frontend', 'frontend_ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), ) ); } /** * Register settings with sanitization. */ public function xsawrlite_register_settings() { register_setting( 'xsawrlite_options', 'xsawrlite-masteroptions', array( 'type' => 'array', 'sanitize_callback' => 'xsawrlite_sanitize_master_options', ) ); } /** * Add/update redirects (AJAX). */ public function xsawrlite_add_redirects() { $this->xsawrlite_verify_ajax_admin(); // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verified in xsawrlite_verify_ajax_admin(). $datajson = array(); $redirects = get_option( 'xsawrlite_easy_redirect', array() ); if ( ! is_array( $redirects ) ) { $redirects = array(); } if ( empty( $redirects ) ) { $index = 0; } else { end( $redirects ); $index = key( $redirects ); } if ( empty( $_POST['redirect_data'] ) ) { $datajson['error'] = esc_html__( 'Invalid request.', 'advance-wp-redirect' ); wp_send_json( $datajson ); } // Do not use sanitize_textarea_field() on the serialized string: WordPress _sanitize_text_fields() // strips all %XX sequences, which breaks bracketed field names and decodes URLs (e.g. %2F, %3A). $xsawrlite_redirect = array(); parse_str( wp_unslash( $_POST['redirect_data'] ), $xsawrlite_redirect ); if ( empty( $xsawrlite_redirect['xsawrlite_easy_redirect'] ) || ! is_array( $xsawrlite_redirect['xsawrlite_easy_redirect'] ) ) { $datajson['error'] = esc_html__( 'Invalid redirect data.', 'advance-wp-redirect' ); wp_send_json( $datajson ); } $row =& $xsawrlite_redirect['xsawrlite_easy_redirect']; $http = isset( $_SERVER['HTTP_ORIGIN'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_ORIGIN'] ) ) : ''; $server_name = isset( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : ''; $order = array_filter( array( $http, '/' . $server_name, $server_name ) ); $rurl_raw = isset( $row['rurl'] ) ? $row['rurl'] : ''; $rurl = $rurl_raw; foreach ( $order as $strip ) { if ( $strip !== '' ) { $rurl = str_replace( $strip, '', $rurl ); } } $row['rurl'] = $rurl; if ( ! isset( $row['rurl'] ) || '' === trim( (string) $row['rurl'] ) ) { $datajson['error'] = esc_html__( 'Please Enter Request URL', 'advance-wp-redirect' ); } $slash = substr( (string) $row['rurl'], 0, 1 ); if ( '/' !== $slash ) { $row['rurl'] = '/' . $rurl; } else { $row['rurl'] = $rurl; } if ( ! isset( $row['nw'] ) ) { if ( isset( $row['nf'] ) ) { $temp1 = $row['nf']; unset( $row['nf'] ); $row['nw'] = '0'; $row['nf'] = $temp1; } else { $row['nw'] = '0'; } } if ( ! isset( $row['nf'] ) ) { $row['nf'] = '0'; } if ( ! isset( $_POST['redirect_id'] ) ) { $rurls = array_column( $redirects, 'rurl' ); if ( in_array( $row['rurl'], $rurls, true ) ) { $datajson['error'] = esc_html__( 'Request URL Already Exist', 'advance-wp-redirect' ); } else { $redirects[ $index + 1 ] = $row; $datajson['success'] = esc_html__( 'Added Redirect Successfully', 'advance-wp-redirect' ); } } else { $xsawr_id = sanitize_text_field( wp_unslash( $_POST['redirect_id'] ) ); if ( ! isset( $redirects[ $xsawr_id ] ) ) { $datajson['error'] = esc_html__( 'Redirect not found.', 'advance-wp-redirect' ); wp_send_json( $datajson ); } $redirects[ $xsawr_id ] = $row; $datajson['updated'] = esc_html__( 'Updated Redirect Successfully', 'advance-wp-redirect' ); } if ( ! isset( $row['durl'] ) || '' === trim( (string) $row['durl'] ) ) { $datajson['error'] = esc_html__( 'Please Enter Target URL', 'advance-wp-redirect' ); } if ( ! isset( $datajson['error'] ) ) { $redirects = array_map( 'xsawrlite_sanitize_redirect_entry', $redirects ); update_option( 'xsawrlite_easy_redirect', $redirects ); $datajson['output'] = $this->xsawrlite_redirect_table_rows_html(); } // phpcs:enable WordPress.Security.NonceVerification.Missing wp_send_json( $datajson ); } /** * Build tbody rows HTML for redirect table. * * @return string */ private function xsawrlite_redirect_table_rows_html() { $output = ''; $xsawrlite_eredirect = get_option( 'xsawrlite_easy_redirect', array() ); if ( ! is_array( $xsawrlite_eredirect ) ) { return $output; } foreach ( $xsawrlite_eredirect as $xsawrlite_key => $val ) { if ( ! is_array( $val ) ) { continue; } $xsawrlite_key_attr = esc_attr( (string) $xsawrlite_key ); $xsawrlite_key_html = esc_html( (string) $xsawrlite_key ); $output .= ''; $output .= '' . $xsawrlite_key_html . ''; $output .= ''; if ( ! empty( $val['title'] ) ) { $output .= esc_html( (string) $val['title'] ); } else { $output .= esc_html( isset( $val['rurl'] ) ? (string) $val['rurl'] : '' ); } if ( ! empty( $val['durl'] ) ) { $output .= '
' . esc_html( (string) $val['durl'] ); } $output .= ''; $output .= '' . esc_html( isset( $val['qp_rule'] ) ? (string) $val['qp_rule'] : '' ) . ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; } return $output; } /** * Delete redirect (AJAX). */ public function xsawrlite_del() { $this->xsawrlite_verify_ajax_admin(); // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verified in xsawrlite_verify_ajax_admin(). if ( empty( $_POST['redirect_id'] ) ) { wp_send_json( array( 'msg' => '' ) ); } $data = get_option( 'xsawrlite_easy_redirect', array() ); if ( ! is_array( $data ) ) { $data = array(); } $id = sanitize_text_field( wp_unslash( $_POST['redirect_id'] ) ); unset( $data[ $id ] ); update_option( 'xsawrlite_easy_redirect', $data ); // phpcs:enable WordPress.Security.NonceVerification.Missing wp_send_json( array( 'msg' => esc_html__( 'Deleted Redirect Successfully', 'advance-wp-redirect' ), ) ); } /** * Edit redirect row (AJAX HTML). */ public function xsawrlite_edit_redirects() { $this->xsawrlite_verify_ajax_admin(); // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verified in xsawrlite_verify_ajax_admin(). if ( empty( $_POST['redirect_id'] ) ) { wp_die( esc_html__( 'Invalid request.', 'advance-wp-redirect' ) ); } $id = sanitize_text_field( wp_unslash( $_POST['redirect_id'] ) ); // phpcs:enable WordPress.Security.NonceVerification.Missing $redirects = get_option( 'xsawrlite_easy_redirect', array() ); if ( ! is_array( $redirects ) || ! isset( $redirects[ $id ] ) ) { wp_die( esc_html__( 'Redirect not found.', 'advance-wp-redirect' ) ); } $data = wp_parse_args( $redirects[ $id ], array( 'rurl' => '', 'durl' => '', 'qp' => 'exact', 'match' => 'durl', 'matched' => 'redirect_url', 'qp_rule' => '302', 'title' => '', 'nf' => '0', 'nw' => '0', ) ); $id_attr = esc_attr( $id ); ?>

399 ) { $status = 302; } // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Targets are admin-configured URLs (may be external). wp_redirect( $target, $status ); exit; } } } /** * Optional 404 → homepage. */ public function xsawrlite_redirect_url_404() { $master_options = get_option( 'xsawrlite-masteroptions', array() ); if ( ! is_array( $master_options ) || isset( $master_options['off-redirect'] ) ) { return; } if ( is_404() && isset( $master_options['404-redirect'] ) ) { wp_safe_redirect( home_url(), 302 ); exit; } } /** * Support form mail (AJAX). */ public function xsawrlite_send_mail() { $this->xsawrlite_verify_ajax_admin(); // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verified in xsawrlite_verify_ajax_admin(). if ( empty( $_POST['data'] ) ) { wp_send_json( array( 'status' => false ) ); } $data = array(); parse_str( wp_unslash( $_POST['data'] ), $data ); // phpcs:enable WordPress.Security.NonceVerification.Missing $type = isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : ''; if ( ! in_array( $type, array( 'report', 'hire', 'request' ), true ) ) { wp_send_json( array( 'status' => false ) ); } $data['plugin_name'] = 'Post Redirection'; $data['version'] = 'lite'; $scheme = is_ssl() ? 'https' : 'http'; $host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : ''; $data['website'] = $host ? $scheme . '://' . $host : ''; $name = isset( $data['xsawrlite_name'] ) ? sanitize_text_field( $data['xsawrlite_name'] ) : ''; $email = isset( $data['xsawrlite_email'] ) ? sanitize_email( $data['xsawrlite_email'] ) : ''; $message = isset( $data['xsawrlite_message'] ) ? sanitize_textarea_field( $data['xsawrlite_message'] ) : ''; $to = 'xfinitysoft@gmail.com'; switch ( $type ) { case 'report': $subject = 'Report a bug'; break; case 'hire': $subject = 'Hire us to customize/develope Plugin/Theme or WordPress projects'; break; default: $subject = 'Request a Feature'; break; } $body = ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= ''; $body .= '
User Name' . esc_html( $name ) . '
User email' . esc_html( $email ) . '
Plugin Name' . esc_html( $data['plugin_name'] ) . '
Version' . esc_html( $data['version'] ) . '
Website' . esc_html( $data['website'] ) . '
Message' . esc_html( $message ) . '
'; $headers = array( 'Content-Type: text/html; charset=UTF-8' ); $params = array( 'name' => rawurlencode( $name ), 'email' => rawurlencode( $email ), 'site' => rawurlencode( $data['website'] ), 'version' => rawurlencode( $data['version'] ), 'plugin_name' => rawurlencode( $data['plugin_name'] ), 'type' => rawurlencode( $type ), 'message' => rawurlencode( $message ), ); $url = add_query_arg( $params, 'https://xfinitysoft.com/wp-json/plugin/v1/quote/save/' ); $server_response = wp_remote_post( esc_url_raw( $url ) ); $api_body = wp_remote_retrieve_body( $server_response ); $se_api_response = json_decode( $api_body, true ); if ( is_array( $se_api_response ) && ! empty( $se_api_response['status'] ) ) { wp_mail( $to, $subject, $body, $headers ); wp_send_json( array( 'status' => true ) ); } wp_send_json( array( 'status' => false ) ); } }