Plugin Directory

Changeset 3430186


Ignore:
Timestamp:
12/31/2025 03:47:14 PM (3 months ago)
Author:
surflabtech
Message:

v2.3.1

Location:
surflink
Files:
301 added
8 edited

Legend:

Unmodified
Added
Removed
  • surflink/trunk/assets/js/redirects.js

    r3428366 r3430186  
    132132   */
    133133
     134  function ob_redirect_list(res) {
     135    const redirect_html = res.data.redirect_html || false;
     136
     137    if (redirect_html) {
     138      $("#surfl-redirect-content").html(redirect_html);
     139    }
     140  }
     141
    134142  // "Select all" checkbox to toggle all bulk checkboxes
    135143  $(document).on("change", "#surfl-redirect-bulk-select-all", function () {
     
    186194        return;
    187195      }
    188       const btn = $(this);
    189       const btnText = btn.text();
    190 
    191       changeBtnState(btn);
     196
     197      let btn;
     198      let btnText;
     199      if (action !== "empty_redirects") {
     200        btn = $(this);
     201        btnText = btn.text();
     202        changeBtnState(btn);
     203      }
     204
    192205      showCustomConfirm(
    193206        "Are you sure you want to delete the selected redirects?",
     
    215228                  "#surfl-redirects-table-notification"
    216229                );
    217                 setTimeout(() => location.reload(), 1500);
     230                ob_redirect_list(response);
    218231              } else {
    219232                showNotification(
     
    266279        function (confirmed) {
    267280          if (confirmed) {
    268             var nonce = $("#surfl-redirect-bulk-action-apply").data("nonce");
     281       
    269282            $.post(SURFL_AJAX_REDIRECTS.ajaxurl, {
    270283              action: "surfl_empty_redirects",
    271284              security: SURFL_AJAX_REDIRECTS.nonce,
    272285            }).done(function (response) {
    273               changeBtnState(btn, btnText);
    274286              if (response.success) {
    275                 location.reload(); // Reload the page to reflect changes
     287                ob_redirect_list(response);
    276288              } else {
    277289                showNotification(
     
    337349          "#surfl-redirect-form-notice"
    338350        );
    339         location.reload();
     351        ob_redirect_list(response);
    340352      } else {
    341353        showNotification(
     
    407419        );
    408420
    409         location.reload();
     421        ob_redirect_list(response);
    410422      } else {
    411423        showNotification(
     
    520532          "#surfl-edit-redirect-modal-message"
    521533        );
    522         location.reload(); // or dynamically update the table if you prefer
     534            changeBtnState(btn, btnText);
     535        ob_redirect_list(response);
    523536      },
    524537      error: function () {
     
    555568              "#surfl-edit-redirect-modal-message"
    556569            );
    557             if (response.success) {
    558               location.reload();
    559             }
    560570            changeBtnState(btn, btnText);
     571            ob_redirect_list(response);
    561572          });
    562573        }
     
    593604                }
    594605              });
    595               setTimeout(() => location.reload(), 1500);
    596606            } else {
    597607              showNotification(
     
    674684      processData: false,
    675685    }).done(function (res) {
     686
     687        changeBtnState(btn, btnText);
    676688      if (res.success) {
     689
     690       
     691        ob_redirect_list(res);
    677692        showNotification(
    678693          "info",
     
    680695          "#surfl-imp-ex-notice"
    681696        );
    682 
    683         setTimeout(function () {
    684           location.reload();
    685         }, 1000);
    686697      } else {
    687698        showNotification("error", res.data.message, "#surfl-imp-ex-notice");
    688699      }
    689700
    690       changeBtnState(btn, btnText);
     701   
    691702    });
    692703  });
     
    858869 */
    859870jQuery(document).ready(function ($) {
     871
     872
     873
     874    function ob_gone_list(res) {
     875    const gone_html = res.data.gone_html || false;
     876
     877    if (gone_html) {
     878      $("#surfl-gone-content").html(gone_html);
     879    }
     880  }
    860881  //handle single 410
     882
     883
     884
    861885
    862886  $(document).on("submit", "#surfl-410-form", function (e) {
     
    879903      },
    880904      success: function (response) {
     905       
     906          changeBtnState(btn, btnText);
    881907        if (response.success) {
     908
    882909          showNotification(
    883910            "success",
     
    885912            "#surfl-410-response-msg"
    886913          );
    887           location.reload();
     914         ob_gone_list(response);
    888915        } else {
    889916          showNotification(
     
    893920          );
    894921        }
    895         changeBtnState(btn, btnText);
     922       
    896923      },
    897924      error: function (xhr, status, error) {
     
    959986      }
    960987
    961       const btn = $(this);
    962       const btnText = btn.text();
    963 
    964       changeBtnState(btn);
     988      let btn ;
     989      let btnText ;
     990
     991   if (action != "surfl_empty_410")
     992   {
     993      btn = $(this);
     994      btnText = btn.text();
     995        changeBtnState(btn); 
     996   }
     997
     998     
     999   
    9651000      showCustomConfirm(
    9661001        "Are you sure you want to delete the selected 410s? This action cannot be undone.",
     
    9901025                );
    9911026
    992                 setTimeout(() => location.reload(), 1500);
     1027                setTimeout(() =>  ob_gone_list(response), 1500);
    9931028              } else {
    9941029                showNotification(
     
    10121047              _wpnonce: nonce,
    10131048            }).done(function (response) {
    1014               changeBtnState(btn, btnText);
     1049     
    10151050              if (response.success) {
    1016                 location.reload(); // Reload the page to reflect changes
     1051               ob_gone_list(response);
    10171052              } else {
    10181053                showNotification(
     
    10831118      processData: false,
    10841119    }).done(function (res) {
     1120       changeBtnState(btn, btnText);
    10851121      if (res.success) {
    10861122        showNotification(
     
    10911127
    10921128        setTimeout(function () {
    1093           location.reload();
     1129          ob_gone_list(res);
    10941130        }, 1000);
    10951131      } else {
     
    10971133      }
    10981134
    1099       changeBtnState(btn, btnText);
     1135   
    11001136    });
    11011137  });
     
    11691205          "#surfl-410-edit-msg"
    11701206        );
    1171         location.reload(); // or dynamically update the table if you prefer
     1207        changeBtnState(btn, btnText);
     1208       ob_gone_list(response);
    11721209      },
    11731210      error: function () {
     
    11831220  $(document).on("click", "#surfl-delete-410-edit", function () {
    11841221    showCustomConfirm(
    1185       "Are you sure you want to delete this redirect?",
     1222      "Are you sure you want to delete this 410?",
    11861223      function (confirmed) {
    11871224        if (confirmed) {
     
    11971234              "#surfl-410-edit-msg"
    11981235            );
    1199             if (response.success) {
    1200               location.reload();
    1201             }
     1236             ob_gone_list(response);
    12021237          });
    12031238        }
     
    12331268              });
    12341269
    1235               setTimeout(() => location.reload(), 1500);
     1270              setTimeout(() =>  ob_gone_list(response), 1500);
    12361271            }
    12371272          });
  • surflink/trunk/assets/js/surfl.js

    r3429290 r3430186  
    325325        } catch (error) {
    326326          console.error(error);
    327           // alert("Error loading tab content. Please try again.");
     327         
    328328        }
    329329      }
  • surflink/trunk/includes/class-surfl-404.php

    r3428732 r3430186  
    132132            : '';
    133133    }
     134
     135        public function create_match_path($source)
     136    {
     137
     138     
     139
     140            // 1. Remove Query Parameters (e.g. /path?foo=bar -> /path)
     141            $path_part = strtok($source, '?');
     142
     143            // 2. Trim BOTH slashes (e.g. /path/ -> path)
     144            $path_part = trim($path_part, '/');
     145
     146            // 3. Lowercase (Valid format for consistent matching)
     147            $clean_path = strtolower($path_part);
     148     
     149
     150        return $clean_path;
     151    }
    134152    public function ajax_bulk_make_410()
    135153    {
     
    162180
    163181            if (!$exists) {
     182
     183                $match_path = $this->create_match_path($normalized_url);
    164184                $inserted = $wpdb->insert($table_410, [
    165185                    'url' => $normalized_url,
     186                    'match_path' => $match_path,
    166187                    'time' => current_time('mysql')
    167188                ]);
  • surflink/trunk/includes/class-surfl-410.php

    r3428732 r3430186  
    88    private $table_name;
    99
     10    const GONE_DB_VERSION = '1.0.1';
     11
     12    const GONE_DB_VERSION_NAME = 'surfl_410_db_version';
     13
    1014    public function __construct() {
    1115        global $wpdb;
    1216        $this->table_name = $wpdb->prefix . 'surflink_410';
    13         $this->activate();
     17        $installed_ver = get_option( self::GONE_DB_VERSION_NAME, '1.0.0' );
     18        if ( version_compare( $installed_ver, self::GONE_DB_VERSION, '<' ) ) {
     19            $this->activate();
     20            $this->migrate_data_for_optimization();
     21            // <--- CRITICAL STEP
     22            update_option( self::GONE_DB_VERSION_NAME, self::GONE_DB_VERSION );
     23        }
    1424        // Front-end hook: before the 404 logger runs, check if URL must send a 410.
    1525        add_action( 'template_redirect', [$this, 'maybe_send_410'], 1 );
     
    2939        global $wpdb;
    3040        $table_name = $this->table_name;
    31         if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) != $table_name ) {
    32             $charset_collate = $wpdb->get_charset_collate();
    33             $sql = "CREATE TABLE {$table_name} (\r\n            id mediumint(9) NOT NULL AUTO_INCREMENT,\r\n            url varchar(255) NOT NULL,\r\n            time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,\r\n            ignore_trailing_slash TINYINT(1) DEFAULT 1,\r\n            ignore_case TINYINT(1) DEFAULT 1,\r\n            ignore_params TINYINT(1) DEFAULT 1,\r\n            is_regex TINYINT(1) DEFAULT 0,\r\n            PRIMARY KEY  (id)\r\n        ) {$charset_collate};";
    34             require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    35             dbDelta( $sql );
    36         }
     41        $charset_collate = $wpdb->get_charset_collate();
     42        $sql = "CREATE TABLE {$table_name} (\r\n            id mediumint(9) NOT NULL AUTO_INCREMENT,\r\n            url TEXT NOT NULL,\r\n            match_path VARCHAR(191) NOT NULL,\r\n            time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,\r\n            ignore_trailing_slash TINYINT(1) DEFAULT 1,\r\n            ignore_case TINYINT(1) DEFAULT 1,\r\n            ignore_params TINYINT(1) DEFAULT 1,\r\n            is_regex TINYINT(1) DEFAULT 0,\r\n            PRIMARY KEY  (id),\r\n            KEY match_path (match_path)\r\n        ) {$charset_collate};";
     43        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     44        dbDelta( $sql );
     45    }
     46
     47    private function migrate_data_for_optimization() {
     48        global $wpdb;
     49        // Select ID, Source, and Type for ALL rows
     50        // We process everything to ensure the column isn't NULL
     51        $rows = $wpdb->get_results( "SELECT id, url FROM {$this->table_name}" );
     52        if ( empty( $rows ) ) {
     53            return;
     54        }
     55        foreach ( $rows as $row ) {
     56            $match_path = '';
     57            $match_path = $this->create_match_path( $row->url );
     58            // Update the database
     59            $wpdb->update(
     60                $this->table_name,
     61                [
     62                    'match_path' => $match_path,
     63                ],
     64                [
     65                    'id' => $row->id,
     66                ],
     67                ['%s'],
     68                ['%d']
     69            );
     70        }
     71    }
     72
     73    public function create_match_path( $source ) {
     74        // 1. Remove Query Parameters (e.g. /path?foo=bar -> /path)
     75        $path_part = strtok( $source, '?' );
     76        // 2. Trim BOTH slashes (e.g. /path/ -> path)
     77        $path_part = trim( $path_part, '/' );
     78        // 3. Lowercase (Valid format for consistent matching)
     79        $clean_path = strtolower( $path_part );
     80        return $clean_path;
     81    }
     82
     83    public function ob_gone_list() {
     84        ob_start();
     85        $this->display_410_manager_page();
     86        return ob_get_clean();
    3787    }
    3888
     
    4494        global $wpdb;
    4595        $current_path = $this->normalize_path( $_SERVER['REQUEST_URI'] );
    46         $urls = $wpdb->get_results( "SELECT * FROM {$this->table_name}" );
     96        $match_path = $this->create_match_path( $current_path );
     97        $urls = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE match_path = %s", $match_path ) );
    4798        foreach ( $urls as $url ) {
    4899            if ( $url->is_regex ) {
     
    163214            ] );
    164215        }
     216        $match_path = $this->create_match_path( $url );
    165217        $inserted = $wpdb->insert( $table, [
    166218            'url'                   => $url,
     
    169221            'ignore_params'         => $ignore_params,
    170222            'is_regex'              => $is_regex,
     223            'match_path'            => $match_path,
    171224        ] );
    172225        if ( $inserted ) {
     226            $gone_html = $this->ob_gone_list();
    173227            wp_send_json_success( [
    174                 'message' => 'Success !',
     228                'gone_html' => $gone_html,
     229                'message'   => 'Success !',
    175230            ] );
    176231        } else {
     
    207262        }
    208263        global $wpdb;
     264        $match_path = $this->create_match_path( $url );
    209265        $updated = $wpdb->update( $this->table_name, [
    210266            'url'                   => $url,
     
    213269            'ignore_params'         => $ignore_params,
    214270            'is_regex'              => $is_regex,
     271            'match_path'            => $match_path,
    215272        ], [
    216273            'id' => $id,
     
    221278            ] );
    222279        }
     280        $gone_html = $this->ob_gone_list();
    223281        wp_send_json_success( [
    224             'message' => '410 updated successfully.',
     282            'gone_html' => $gone_html,
     283            'message'   => '410 updated successfully.',
    225284        ] );
    226285    }
     
    326385        ] );
    327386        if ( $deleted ) {
     387            $gone_html = $this->ob_gone_list();
    328388            wp_send_json_success( [
    329                 'message' => esc_html__( '410 deleted successfully', 'surflink' ),
     389                'gone_html' => $gone_html,
     390                'message'   => esc_html__( '410 deleted successfully', 'surflink' ),
    330391            ] );
    331392        } else {
     
    372433            ] );
    373434        } else {
     435            $gone_html = $this->ob_gone_list();
    374436            wp_send_json_success( [
    375                 'message' => sprintf( _n(
     437                'gone_html' => $gone_html,
     438                'message'   => sprintf( _n(
    376439                    '%d redirect deleted successfully',
    377440                    '%d redirects deleted successfully',
     
    397460        $result = $wpdb->query( $query );
    398461        if ( $result !== false ) {
     462            $gone_html = $this->ob_gone_list();
    399463            wp_send_json_success( [
    400                 'message' => esc_html__( 'Success', 'surflink' ),
     464                'gone_html' => $gone_html,
     465                'message'   => esc_html__( 'Success', 'surflink' ),
    401466            ] );
    402467        } else {
     
    458523        }
    459524        $csv = file_get_contents( $_FILES['file']['tmp_name'] );
    460         $lines = array_map( 'str_getcsv', preg_split( '/\\r\\n|\\r|\\n/', $csv ) );
     525        $lines = array_map( function ( $line ) {
     526            return str_getcsv(
     527                $line,
     528                ',',
     529                '"',
     530                '\\'
     531            );
     532        }, preg_split( '/\\r\\n|\\r|\\n/', $csv ) );
    461533        $lines = array_filter( $lines, function ( $line ) {
    462534            return is_array( $line ) && count( array_filter( $line ) ) > 0;
     
    490562                continue;
    491563            }
     564            $match_path = $this->create_match_path( $url );
    492565            $wpdb->insert( $this->table_name, [
    493                 'url' => $url,
     566                'url'        => $url,
     567                'match_path' => $match_path,
    494568            ] );
    495569            if ( $wpdb->insert_id ) {
     
    497571            }
    498572        }
     573        $gone_html = $this->ob_gone_list();
    499574        wp_send_json_success( [
     575            'gone_html'   => $gone_html,
    500576            'message'     => esc_html__( 'Importing 410 completed', 'surflink' ),
    501577            'imported'    => $inserted,
  • surflink/trunk/includes/class-surfl-loader.php

    r3429598 r3430186  
    401401            require_once SURFL_PATH . 'templates/surfl-redirection-rules.php';
    402402        } elseif ( $active_tab === 'surfl-red-li-tab' ) {
     403            echo '<div id="surfl-redirect-content">';
    403404            set_transient( $tab_transient, $active_tab, 5 * MINUTE_IN_SECONDS );
    404405            $this->surfl_redirect->render_li_red_page();
     406            echo '</div>';
    405407        } elseif ( $active_tab === 'surfl-red-410-tab' ) {
    406408            set_transient( $tab_transient, $active_tab, 5 * MINUTE_IN_SECONDS );
    407409            $this->surfl_410->display_410_page();
    408410        } elseif ( $active_tab === 'surfl-red-410-li-tab' ) {
     411            echo '<div id="surfl-gone-content">';
    409412            set_transient( $tab_transient, $active_tab, 5 * MINUTE_IN_SECONDS );
    410413            $this->surfl_410->display_410_manager_page();
     414            echo '</div>';
    411415        } elseif ( $active_tab === 'surfl-red-404l-tab' ) {
    412416            set_transient( $tab_transient, $active_tab, 5 * MINUTE_IN_SECONDS );
  • surflink/trunk/includes/class-surfl-redirect.php

    r3429799 r3430186  
    235235        ] );
    236236        if ( $wpdb->insert_id ) {
     237            $redirect_html = $this->ob_redirect_list();
    237238            wp_send_json_success( [
    238239                'id'                    => $wpdb->insert_id,
     
    322323                $message .= '<br>' . implode( '<br>', $errors );
    323324            }
     325            $redirect_html = $this->ob_redirect_list();
    324326            wp_send_json_success( [
    325                 'message' => $message,
     327                'redirect_html' => $redirect_html,
     328                'message'       => $message,
    326329            ] );
    327330        } else {
     
    350353        ] );
    351354        if ( $deleted ) {
     355            $redirect_html = $this->ob_redirect_list();
    352356            wp_send_json_success( [
    353                 'message' => esc_html__( 'Redirect deleted successfully', 'surflink' ),
     357                'redirect_html' => $redirect_html,
     358                'message'       => esc_html__( 'Redirect deleted successfully', 'surflink' ),
    354359            ] );
    355360        } else {
     
    526531        $result = $wpdb->query( $query );
    527532        if ( $result !== false ) {
     533            $redirect_html = $this->ob_redirect_list();
    528534            wp_send_json_success( [
    529                 'message' => esc_html__( 'Selected redirects deleted successfully', 'surflink' ),
     535                'redirect_html' => $redirect_html,
     536                'message'       => esc_html__( 'Selected redirects deleted successfully', 'surflink' ),
    530537            ] );
    531538        } else {
     
    571578            ] );
    572579        } else {
     580            $redirect_html = $this->ob_redirect_list();
    573581            wp_send_json_success( [
    574                 'message' => sprintf( _n(
     582                'redirect_html' => $redirect_html,
     583                'message'       => sprintf( _n(
    575584                    '%d redirect updated.',
    576585                    '%d redirects updated.',
     
    594603        $result = $wpdb->query( $query );
    595604        if ( $result !== false ) {
     605            $redirect_html = $this->ob_redirect_list();
    596606            wp_send_json_success( [
    597                 'message' => esc_html__( 'Success', 'surflink' ),
     607                'redirect_html' => $redirect_html,
     608                'message'       => esc_html__( 'Success', 'surflink' ),
    598609            ] );
    599610        } else {
     
    661672        }
    662673        $csv = file_get_contents( $_FILES['file']['tmp_name'] );
    663         $lines = array_map( 'str_getcsv', preg_split( '/\\r\\n|\\r|\\n/', $csv ) );
     674        $lines = array_map( function ( $line ) {
     675            return str_getcsv(
     676                $line,
     677                ',',
     678                '"',
     679                '\\'
     680            );
     681        }, preg_split( '/\\r\\n|\\r|\\n/', $csv ) );
    664682        $lines = array_filter( $lines, function ( $line ) {
    665683            return is_array( $line ) && count( array_filter( $line ) ) > 0;
     
    715733            }
    716734        }
     735        $redirect_html = $this->ob_redirect_list();
    717736        wp_send_json_success( [
    718             'message'     => esc_html__( 'Importing Redirects completed', 'surflink' ),
    719             'imported'    => $inserted,
    720             'duplication' => $duplication,
    721             'error'       => $error,
     737            'redirect_html' => $redirect_html,
     738            'message'       => esc_html__( 'Importing Redirects completed', 'surflink' ),
     739            'imported'      => $inserted,
     740            'duplication'   => $duplication,
     741            'error'         => $error,
    722742        ] );
    723743    }
     
    793813            ] );
    794814        }
     815        $redirect_html = $this->ob_redirect_list();
    795816        wp_send_json_success( [
    796             'message' => "Redirect rules updated successfully.",
     817            'message'       => "Redirect rules updated successfully.",
     818            'redirect_html' => $redirect_html,
    797819        ] );
    798820    }
     
    830852    }
    831853
     854    public function ob_redirect_list() {
     855        ob_start();
     856        $this->render_li_red_page();
     857        return ob_get_clean();
     858    }
     859
    832860    public function halt_bg( $slug = 'surfl-redirects' ) {
    833861        if ( !$this->is_module_enabled( $slug ) && $this->is_background_disabled( $slug ) ) {
  • surflink/trunk/readme.txt

    r3429799 r3430186  
    66**Requires PHP:** 7.4   
    77**Tested up to:** 6.9 
    8 **Stable tag:** 2.3.0
     8**Stable tag:** 2.3.1
    99**License:** GPLv3 or later 
    1010**License URI:** https://opensource.org/licenses/GPL-3.0 
     
    141141== Changelog ==
    142142
     143= 2.3.1 =
     144* Improved: UX is improved in Redirects module. And some minor fixes.
     145
    143146= 2.3.0 =
    144147* Performance: More optimized query in case of redirection is optimized for better and faster performance.
  • surflink/trunk/surf-link.php

    r3429799 r3430186  
    77 * Author: SurfLab
    88 * Author URI: https://surflabtech.com
    9  * Version: 2.3.0
     9 * Version: 2.3.1
    1010 * Text Domain: surflink
    1111 * License: GPL-3.0-or-later
     
    6767    }
    6868    if ( !defined( 'SURFL_VERSION' ) ) {
    69         define( 'SURFL_VERSION', '2.3.0' );
     69        define( 'SURFL_VERSION', '2.3.1' );
    7070    }
    7171    if ( !defined( 'SURFL_PLUGIN' ) ) {
     
    9999        }
    100100        if ( !defined( 'SURFL_VERSION' ) ) {
    101             define( 'SURFL_VERSION', '2.3.0' );
     101            define( 'SURFL_VERSION', '2.3.1' );
    102102        }
    103103        if ( !defined( 'SURFL_SITE_URL' ) ) {
Note: See TracChangeset for help on using the changeset viewer.