Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    119

    Mi aiutate a modificare questo script di ricerca ?

    Ho questo script della funzione di ricerca ( che fa parte di un blog opensource, di quelli senza database).

    Vorrei modificarlo.

    Vorrei fare in modo che anzichè avere un campo vuoto per la ricerca avesse un menù a tendina con 4 o + scelte preimpostate.



    Codice PHP:
    <?php 

        
    // ----------------
        // Search Functions
        // ----------------
        
        
    function search $search_str$max_results=10 ) {
            
    // Search in contents feature a list of keywords separated by spaces
        
            // Read entries by month, year and/or day. Generate HTML output.
            //
            // Used for the main Index page.
            
    global $lang_string$blog_config$user_colors;
            
            
    // To avoid server overload
            
    sleep(1);
            
            
    $output_str '';
            
            
    $entry_file_array blog_entry_listing();

            
    $words=@split' 'strtoupper$search_str ) );
            
            if ( 
    strlen$search_str ) > 1) {
                for ( 
    $i 0$i count$words ); $i++) {
                    
    $words[$i] = trim($words[$i] );
                }
                
                if ( 
    $max_results <= ) {
                    
    $max_results=10;
                }
                
                
    $results=0;
                
    // Loop through entry files
                
    for ( $i 0$i count$entry_file_array ); $i++ ) {
                    if ( 
    $results $max_results ) {
                        break;
                    }
                
                    list( 
    $entry_filename$year_dir$month_dir ) = explode'|'$entry_file_array$i ] );
                    
    $contents sb_read_fileCONTENT_DIR $year_dir '/' $month_dir '/' $entry_filename );
                    
    $j 0;
                    
    $found true;
                    
    $text strtoupper$contents );
                    while ( ( 
    $j<count$words ) ) && ( $found ) ) {
                        if ( 
    $words[$j] !== '' ) {
                            
    $found $found && ( strpos$text$words[$j] ) !== false );
                        }
                        
    $j++;
                    }
                    if ( 
    $found ) {
                        
    $results++;
                        
    $blog_entry_data blog_entry_to_arrayCONTENT_DIR $year_dir '/' $month_dir '/' $entry_filename );
                        
    $output_str  .= '[url="index.php?entry=' sb_strip_extension$entry_filename ) . '"]' $blog_entry_data'SUBJECT' ] . '[/url]
    '
    ;
                    }
                    
    // Search Comments
                    
    if ( $blog_config'blog_enable_comments' ] == true ) {
                        
    $comment_file_array sb_folder_listingCONTENT_DIR $year_dir '/' $month_dir '/' sb_strip_extension$entry_filename ) . '/comments/', array( '.txt''.gz' ) );
         
                        for ( 
    $k 0$k count$comment_file_array ); $k++ ) {
                            
    $comment_filename =  $comment_file_array$k ];
                            
    //We only want to search inside comments, not the counter
                            
    if ( strpos($comment_filename'comment') === )
                            {
                                
    $contents_comment sb_read_fileCONTENT_DIR $year_dir '/' $month_dir '/' sb_strip_extension$entry_filename ) . '/comments/' $comment_filename );
                                
    $found_in_comment true;
                                
    $l 0;
                                
    $text strtoupper$contents_comment );
                                while ( ( 
    $lcount$words ) ) && ( $found_in_comment ) ) {
                                    if ( 
    $words[$l] !== '' ) {
                                        
    $found_in_comment $found_in_comment && ( strpos$text$words[$l] ) !== false );
                                    }
                                    
    $l++;
                                }
                                if ( 
    $found_in_comment ) {
                                    
    $results++;
                                    if ( 
    $found == false ) {
                                        
    // list( $blog_subject, $blog_date, $blog_text ) = explode('|', ( $contents ) );
                                        
    $blog_entry_data blog_entry_to_arrayCONTENT_DIR $year_dir '/' $month_dir '/' $entry_filename );
                                        
    $output_str  .= $blog_entry_data'SUBJECT' ] . '
    '
    ;
                                    }
                                    
                                    
    // list( $comment_author, $comment_date, $comment_text ) = explode('|', ( $contents_comment ) );
                                    
    $comment_entry_data comment_to_arrayCONTENT_DIR $year_dir '/' $month_dir '/' sb_strip_extension$entry_filename ) . '/comments/' $comment_filename );

                                    global 
    $theme_vars;
                                    if ( 
    $blog_config'blog_comments_popup' ] == ) {
                                        
    $output_str  .= '[url="javascript:openpopup(\'comments.php?y='.$year_dir.'&amp;m='.$month_dir.'&amp;entry='sb_strip_extension($entry_filename).'\','.$theme_vars'popup_window' ][ 'width' ].','.$theme_vars'popup_window' ][ 'height' ].',true)"]' $comment_entry_data'NAME' ] . '[/url]
    '
    ;
                                    } else {
                                        
    $output_str  .= '[url="comments.php?y=' $year_dir '&amp;m=' $month_dir '&amp;entry=' sb_strip_extension$entry_filename ) . '"]' $comment_entry_data'NAME' ] . '[/url]
    '
    ;
                                    }
                                }
                            }
                        }
                    }
                }
                
    // Search static pages
                
    $static_file_array sb_folder_listingCONTENT_DIR.'static/', array( '.txt''.gz' ) );
                for ( 
    $i 0$i count$static_file_array ); $i++ ) {
                    
    $static_filename =  $static_file_array$i ];
                    
    $contents_static sb_read_fileCONTENT_DIR.'static/' $static_filename );
                    
    $found_in_static true;
                    
    $j 0;
                    
    $text strtoupper$contents_static );
                    while ( ( 
    $jcount$words ) ) && ( $found_in_static ) ) {
                        if ( 
    $words[$j] !== '' ) {
                            
    $found_in_static $found_in_static && ( strpos$text$words[$j] ) !== false );
                        }
                        
    $j++;
                    }
                    if ( 
    $found_in_static ) {
                        
    $results++;
                        
    $blog_static_data static_entry_to_arrayCONTENT_DIR.'static/' $static_filename );
                        
    $output_str  .= '[url="static.php?page=' sb_strip_extension$static_filename ) . '"]' $blog_static_data'SUBJECT' ] . '[/url]
    '
    ;
                    }
                }
            }
            return ( 
    $output_str );
        }
    ?>

  2. #2
    Basta che al posto della imput Textbox gli metti una select... e l'utente dovrà scegliere una delle voci da te preselezionate..

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    119
    Ciao, grazie per la risposta ma...

    in effetti non sono un programmatore php. Mi limito a modificare le parti di codice.

    Mi puoi aiutare a capire meglio ?
    Quale riga devo modificare ?
    Come faccio a inserire le tre opzioni poi ?

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    119
    Troppe domande ? Vi ho spaventato ?


  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    119
    Dunque il codice di ricerca è questo:

    Codice PHP:
    <?php
        
        
    class Search extends Sidebar {
            var 
    $plugin;
            
            
    /* ------ INITIALIZE ------ */
            
            
    function Search () {
                
    $this->plugin 'Search';
                
    $this->loadPrefs();
            }
            
            
    /* ------ GETTERS & SETTERS ------ */
            
            
    function getTitle () {
                return 
    $GLOBALS'lang_string' ][ 'search_title' ];
            }
            
            function 
    getContent () {
                
    $str sprintf('<form method="get" action="search.php">[b]%s[/b]<input type="textbox" size="16" name="q" /><input type="submit" value="%s" /></form>'$GLOBALS'lang_string' ][ 'search_title' ], $GLOBALS'lang_string' ][ 'search_go' ] );
                return 
    $str;
            }
        }
    ?>

    Ho trovato questo esempio di select ma è in html

    Codice PHP:
    <select name="search" id="search" accesskey="1" tabindex="1">
        <
    option value="ricerca1">ricerca1</option>
        <
    option value="ricerca2">ricerca2</option>
        <
    option value="ricerca3">ricerca3</option>
            </
    select
    Posso usare lo stesso codice ?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.