<%
# 3. randomly sample (both contiguous run and scatter) the links to
# check 4 uniqueness against other links in the imported bookmarks
# file as well as uniqueness against the users existing FML links
# (to detect possible linkspammers)
$p = 10; # %
$num_dupes = 0;
$max_dupes_allowed = ceil( $ls / $p / 2 );
if( $max_dupes_allowed < 10 )
$max_dupes_allowed = 10;
$dupe_message = " already exists in your Feed Me Links account.";
# scatter-check: check p % of the input randomly for possible spammage
for( $i = 0; $i < floor( $ls / $p ); $i++ ) {
$line = rtrim( $links[ rand( 0, $ls ) ] );
$l = preg_split( "/$delimeter/", $line );
if( users_link_exists( $u, $l[0] )) {
++$num_dupes;
#l( $l[0] . $dupe_message );
}
}
# contiguous run: pick a random spot in the list and check the next p % in a row
$start_index = rand( 0, $ls - ceil( $ls / $p ));
for( $i = $start_index; $i < $start_index + floor($ls / $p); $i++ ) {
$line = rtrim( $links[$i] );
$l = preg_split( "/$delimeter/", $line );
if( users_link_exists( $u, $l[0] )) {
++$num_dupes;
#l( $l[0] . $dupe_message );
}
}
if( $num_dupes > $max_dupes_allowed ) {
fatal( "We noticed that a percentage ($max_dupes_allowed links) of the links you're importing already exist in your Feed Me Links account. Have you imported this bookmarks file already? If not, please <a href='mailto:hide@address.com'>email the administrators</a> for help importing your favorites." );
exit( 0 );
} # else
#tell( "Debugging Check:", "Found $num_dupes duplicate links (a max of $max_dupes_allowed duplicates is allowed)." );
%>