[dw-free] Search for several interests at once
[commit: http://hg.dwscoalition.org/dw-free/rev/6fc0cc50a979]
http://bugs.dwscoalition.org/show_bug.cgi?id=2821
Refactor out truncation checking, for easier reuse.
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2821
Refactor out truncation checking, for easier reuse.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/DW/Controller/Search/Interests.pm
-------------------------------------------------------------------------------- diff -r acfd5eeeffd6 -r 6fc0cc50a979 cgi-bin/DW/Controller/Search/Interests.pm --- a/cgi-bin/DW/Controller/Search/Interests.pm Mon Oct 03 14:00:05 2011 +0800 +++ b/cgi-bin/DW/Controller/Search/Interests.pm Mon Oct 03 14:05:08 2011 +0800 @@ -264,6 +264,34 @@ } if ( $mode eq 'int' ) { + my $trunc_check = sub { + my ( $check_int, $interest ) = @_; + my $e_int = LJ::ehtml( $check_int ); + + # Determine whether the interest is too long: + # 1. If the interest already exists, a long interest will result + # in $check_int and $interest not matching. + # 2. If it didn't already exist, we fall back on just checking + # the length of $check_int. + + if ( ( $interest && $check_int ne $interest ) || + length( $check_int ) > LJ::CMAX_SITEKEYWORD ) { + + # The searched-for interest is too long, so use the short version. + my $e_int_long = $e_int; + $e_int = LJ::ehtml( $interest ? $interest : + substr( $check_int, 0, LJ::CMAX_SITEKEYWORD ) ); + + $rv->{warn_toolong} = + LJ::Lang::ml( 'interests.error.longinterest', + { sitename => $LJ::SITENAMESHORT, + old_int => $e_int_long, new_int => $e_int, + maxlen => LJ::CMAX_SITEKEYWORD } ); + } + + return $e_int; + }; + my $intarg = LJ::utf8_lc ( $args->{int} ); my $intid = $args->{intid} ? $args->{intid} + 0 : LJ::get_sitekeyword_id( $intarg, 0 ) || 0; @@ -275,21 +303,7 @@ return error_ml( 'interests.error.ignored' ); } - my $e_int = LJ::ehtml( $check_int ); - # determine whether the interest is too long: - # 1. if the interest already exists, a long interest will result in $check_int and $interest not matching - # 2. if it didn't already exist, we fall back on just checking the length of $check_int - if ( ( $interest && $check_int ne $interest ) || length( $check_int ) > LJ::CMAX_SITEKEYWORD ) { - # if the searched-for interest is too long, we use the short version from here on - my $e_int_long = $e_int; - $e_int = LJ::ehtml( $interest ? $interest : substr( $check_int, 0, LJ::CMAX_SITEKEYWORD ) ); - $rv->{warn_toolong} = - LJ::Lang::ml( 'interests.error.longinterest', - { sitename => $LJ::SITENAMESHORT, - old_int => $e_int_long, new_int => $e_int, - maxlen => LJ::CMAX_SITEKEYWORD } ); - } - $rv->{e_int} = $e_int; + $rv->{e_int} = $trunc_check->( $check_int, $interest ); $rv->{interest} = $interest; $rv->{intid} = $intid; $rv->{intcount} = $intcount; --------------------------------------------------------------------------------