Skip to content

Commit

Permalink
add hyperlinks to redirects causing loops
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Aug 28, 2023
1 parent cfdeb13 commit cc11274
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
16 changes: 11 additions & 5 deletions inc/classes/class-srm-loop-detection.php
Expand Up @@ -62,7 +62,10 @@ private static function get_directed_graph() {
}

// Add an edge from the source URL to the destination URL.
$graph[ $source_url ][] = $destination_url;
$graph[ $source_url ][] = array(
'id' => $redirect['ID'],
'destination' => $destination_url,
);
}
}

Expand All @@ -88,9 +91,9 @@ private static function has_cycle_recursive( $graph, $vertex, &$visited, &$curre

if ( isset( $graph[ $vertex ] ) ) {
foreach ( $graph[ $vertex ] as $neighbor ) {
if ( ! isset( $visited[ $neighbor ] ) ) {
self::has_cycle_recursive( $graph, $neighbor, $visited, $current_path, $cycle_source );
} elseif ( isset( $current_path[ $neighbor ] ) ) {
if ( ! isset( $visited[ $neighbor['destination'] ] ) ) {
self::has_cycle_recursive( $graph, $neighbor['destination'], $visited, $current_path, $cycle_source );
} elseif ( isset( $current_path[ $neighbor['destination'] ] ) ) {
$cycle_source[] = $neighbor;
}
}
Expand Down Expand Up @@ -131,7 +134,10 @@ public static function detect_redirect_loops() {
public static function get_cycle_source( $cycle_source = array() ) {
return array_map(
function( $source ) {
return wp_parse_url( esc_url( $source ), PHP_URL_PATH );
return array(
'path' => wp_parse_url( esc_url( $source['destination'] ), PHP_URL_PATH ),
'id' => $source['id'],
);
},
$cycle_source
);
Expand Down
16 changes: 12 additions & 4 deletions inc/classes/class-srm-post-type.php
Expand Up @@ -242,10 +242,18 @@ public function action_redirect_chain_alert() {
if ( ! empty( $cycle_source ) ) {
?>
<div class="notice notice-warning">
<p><?php esc_html_e( 'Safe Redirect Manager Warning: The following redirects with the "Redirect From" value have been detected as a starting point of redirect chain/loops.', 'safe-redirect-manager' ); ?></p>
<p><?php esc_html_e( 'Safe Redirect Manager Warning: The following redirects with the "Redirect To" value have created redirect chain/loops.', 'safe-redirect-manager' ); ?></p>
<ul style="list-style: inside;">
<?php foreach ( $paths as $path ) : ?>
<li><?php echo esc_html( $path ); ?></li>
<li>
<?php
printf(
'<a href="%s">%s</a>',
esc_url( get_edit_post_link( esc_html( $path['id'] ) ) ),
esc_html( $path['path'] )
);
?>
</li>
<?php endforeach; ?>
</ul style>
</div>
Expand Down Expand Up @@ -719,8 +727,8 @@ public function load_resources() {
'redirectjs',
'redirectValidation',
array(
'urlError' => __( 'There are some issues validating the URL. Please try again.', 'safe-redirect-manager' ),
'fail' => __( 'There is an existing redirect with the same Redirect From URL. You may <a href="%s">Edit</a> the redirect or try other `from` URL.', 'safe-redirect-manager' ),
'urlError' => __( 'There are some issues validating the URL. Please try again.', 'safe-redirect-manager' ),
'fail' => __( 'There is an existing redirect with the same Redirect From URL. You may <a href="%s">Edit</a> the redirect or try other `from` URL.', 'safe-redirect-manager' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'ajax_nonce' => wp_create_nonce( 'srm_autocomplete_nonce' ),
)
Expand Down

0 comments on commit cc11274

Please sign in to comment.