postmeta} where meta_key = 'blogger_blog'"; // unprepared sql ok. $results = $wpdb->get_results( $sql ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.NoCaching require_once RT_B2WR_PLUGIN_DIR . 'templates/get-config.php'; die(); } add_action( 'wp_ajax_rt_b2wr_get_config', 'rt_b2wr_get_config' ); /** * Redirection Function (!important) */ function rt_blogger_to_wordpress_redirection() { global $wpdb; $b2w = filter_input( INPUT_GET, 'b2w', FILTER_SANITIZE_STRING ); $b2w = ( ! empty( $b2w ) ) ? $b2w : false; if ( false === $b2w ) { return; } $sql = "SELECT DISTINCT meta_value FROM {$wpdb->postmeta} where meta_key = 'blogger_blog'"; // unprepared sql ok. $results = $wpdb->get_results( $sql ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.NoCaching foreach ( $results as $result ) { $result->meta_value = substr( $result->meta_value, 0, strrpos( $result->meta_value, '.' ) ); if ( strstr( $b2w, $result->meta_value ) !== false ) { $b2w_temp = explode( $result->meta_value, $b2w ); $b2w = substr( $b2w_temp[1], strpos( $b2w_temp[1], '/' ) ); if ( strpos( $b2w, '?' ) > 0 ) { $b2w = strstr( $b2w, '?', true ); } } $sqlstr = $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'blogger_permalink' AND meta_value = %s", $b2w ); // unprepared sql ok. $wpurl = $wpdb->get_results( $sqlstr, ARRAY_N ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.NoCaching if ( ! empty( $wpurl ) ) { // wp redirect ok. wp_redirect( get_permalink( $wpurl[0][0] ) ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect exit; } else { wp_safe_redirect( home_url(), 301 ); exit; } } } add_action( 'init', 'rt_blogger_to_wordpress_redirection' ); /** * Verify Configuration */ function rt_b2wr_verify_config() { global $wpdb; if ( ! isset( $_POST['config_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['config_nonce'] ) ), 'b2w_code_nonce' ) ) { return; } $domain_name = ( isset( $_POST['dname'] ) ) ? sanitize_text_field( wp_unslash( $_POST['dname'] ) ) : ''; $sql = $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'blogger_blog' AND meta_value = %s ORDER BY rand() LIMIT 1", $domain_name ); // unprepared sql ok. $rand_col = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.NoCaching $rand_post_id = $rand_col[0]->post_id; $sql1 = $wpdb->prepare( "SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = 'blogger_permalink' ORDER BY rand() LIMIT 1", $rand_post_id ); // unprepared sql ok. $rand_col2 = $wpdb->get_results( $sql1 ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.NoCaching $blogger_url = 'https://' . $domain_name . $rand_col2[0]->meta_value; $local_url = get_permalink( $rand_post_id ); require_once RT_B2WR_PLUGIN_DIR . 'templates/verify-config.php'; die(); } add_action( 'wp_ajax_rt_b2wr_verify_config', 'rt_b2wr_verify_config' ); /** * Get Latest Feeds - Begin */ function rt_get_feeds_from_blogger_to_wp() { require_once ABSPATH . WPINC . '/feed.php'; $rss = fetch_feed( 'https://bloggertowp.org/feed/' ); if ( ! is_wp_error( $rss ) ) { $maxitems = $rss->get_item_quantity( 5 ); $rss_items = $rss->get_items( 0, $maxitems ); } require_once RT_B2WR_PLUGIN_DIR . 'templates/feeds.php'; } /** * Update Notice - Begin */ function rt_blogger_to_wordpress_update_notice() { if ( empty( get_option( 'rtb2wr206' ) ) ) { require_once RT_B2WR_PLUGIN_DIR . 'template/update-notice.php'; } } /** * Hide Notice block */ function rt_b2wr_hide_notice_block() { if ( ! isset( $_POST['update_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['update_nonce'] ) ), 'b2w_update_nonce' ) ) { return; } update_option( 'rtb2wr206', 'done' ); } add_action( 'wp_ajax_rt_b2wr_hide_notice_block', 'rt_b2wr_hide_notice_block' );