From 1de10bd66f761f8b66dcaecd28f5c2547b754ff3 Mon Sep 17 00:00:00 2001 From: z0rglub Date: Sun, 25 May 2003 08:31:39 +0000 Subject: search improved git-svn-id: http://piwigo.org/svn/trunk@17 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions.inc.php | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'include/functions.inc.php') diff --git a/include/functions.inc.php b/include/functions.inc.php index 5ff119f29..eb8571e86 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -169,7 +169,7 @@ function get_dirs( $rep ) { while ( $file = readdir ( $opendir ) ) { - if ( $file != "." and $file != ".." and is_dir ( $rep.$file ) ) + if ( $file != '.' and $file != '..' and is_dir ( $rep.$file ) ) { array_push( $sub_rep, $file ); } @@ -274,14 +274,14 @@ function get_themes( $theme_dir ) return $themes; } -// - The replace_search function replaces a $search string by the search in -// another color +// - add_style replaces the +// $search into $search +// in the given $string. // - The function does not replace characters in HTML tags -function replace_search( $string, $search ) +function add_style( $string, $search, $style ) { //return $string; - $style_search = "background-color:white;color:red;"; - $return_string = ""; + $return_string = ''; $remaining = $string; $start = 0; @@ -291,21 +291,32 @@ function replace_search( $string, $search ) while ( is_numeric( $start ) and is_numeric( $end ) ) { $treatment = substr ( $remaining, 0, $start ); - $treatment = str_replace( $search, ''. + $treatment = str_replace( $search, ''. $search.'', $treatment ); - $return_string.= $treatment.substr ( $remaining, $start, - $end - $start + 1 ); + $return_string.= $treatment.substr( $remaining, $start, $end-$start+1 ); $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) ); $start = strpos ( $remaining, '<' ); $end = strpos ( $remaining, '>' ); } - $treatment = str_replace( $search, ''. + $treatment = str_replace( $search, ''. $search.'', $remaining ); $return_string.= $treatment; return $return_string; } +// replace_search replaces a searched words array string by the search in +// another style for the given $string. +function replace_search( $string, $search ) +{ + $words = explode( ',', $search ); + $style = 'background-color:white;color:red;'; + foreach ( $words as $word ) { + $string = add_style( $string, $word, $style ); + } + return $string; +} + function database_connection() { // $cfgHote,$cfgUser,$cfgPassword,$cfgBase; -- cgit v1.2.3