70 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
71 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
72 $this->String =
get_package(
'string' ,
'last' , __FILE__ );
102 $Config = $this->CachedMultyFS->get_config( __FILE__ ,
'cf_search_access' ,
'exploded' );
106 foreach( $Config as $i => $ConfigLine )
108 $Settigs->load_settings( $ConfigLine );
110 $PackageName = $Settigs->get_setting(
'package_name' );
111 $PackageVersion = $Settigs->get_setting(
'package_version' );
113 $Packages [] =
get_package( $PackageName , $PackageVersion , __FILE__ );
118 catch( Exception $e )
156 $Limitations = $this->Security->get_gp(
'search_output_limitations' ,
'string' ,
'' );
157 $Limitations = explode(
',' , $Limitations );
159 foreach( $Packages as $i => $Package )
161 $Results [] = call_user_func(
162 array( $Package ,
'search' ) ,
get_field( $Limitations , $i , 0 ) , $SearchString
168 catch( Exception $e )
200 foreach( $Results as $i => $Records )
204 foreach( $Records as $j => $Record )
206 $Relevation = intval(
get_field( $Record ,
'relevation' ) );
207 if( $Relevation > 0 )
209 $Return [] = $Record;
213 $Results[ $i ] = $Return;
218 catch( Exception $e )
252 if( isset( $Records[ 0 ] ) )
254 $MaxRelevation = intval(
get_field( $Records[ 0 ] ,
'relevation' ) );
256 foreach( $Records as $j => $Record )
258 $Tmp = intval(
get_field( $Record ,
'relevation' ) );
259 if( $Tmp > $MaxRelevation )
261 $MaxRelevation = $Tmp;
266 return( $MaxRelevation );
268 catch( Exception $e )
302 foreach( $Results as $i => $Records )
306 foreach( $Records as $j => $Record )
309 $Results[ $i ][ $j ] ,
'relevation' ,
310 intval(
get_field( $Results[ $i ][ $j ] ,
'relevation' ) ) / $MaxRelevation
317 catch( Exception $e )
349 $SearchLine = array();
352 foreach( $Results as $i => $Result )
354 foreach( $Result as $j => $Record )
356 set_field( $Results[ $i ][ $j ] ,
'fetch_id' , $i );
361 foreach( $Results as $i => $Result )
363 $SearchLine = array_merge( $SearchLine , $Result );
366 return( array_slice( $SearchLine , 0 , 10 ) );
368 catch( Exception $e )
400 private function get_preview_paraneters( &$Result , $SearchString )
404 $Position = strpos( $Text =
get_field( $Result ,
'record_text' ) , $SearchString );
405 $Length = strlen( $Text );
407 $LeftBorder = ( $Position - $PreviewSize > 0 ? $Position - $PreviewSize : 0 );
408 $RightBorder = ( $Position + $PreviewSize > $Length ? $Length : $Position + $PreviewSize );
410 return( array( $Length , $LeftBorder , $RightBorder ) );
412 catch( Exception $e )
444 private function compile_preview( &$Result , $SearchString )
448 list( $Length , $LeftBorder , $RightBorder ) = $this->get_preview_paraneters( $Result , $SearchString );
450 $Preview = substr( $Text , $LeftBorder , $RightBorder - $LeftBorder );
452 $Preview = ( $LeftBorder ?
'...' :
'' ).$Preview.( $RightBorder != $Length ?
'...' :
'' );
453 $Highlight = $this->CachedMultyFS->get_template( __FILE__ ,
'search_highlight.tpl' );
454 $Hightlight = str_replace(
'{search_string}' , $SearchString , $Hightlight );
456 $Preview = str_replace( $SearchString , $Hightlight , $Preview );
458 catch( Exception $e )
494 foreach( $SearchLine as $i => $Result )
496 $Preview = $this->compile_preview( $Result , $SearchString );
498 set_field( $SearchLine[ $i ] ,
'record_text' , $Preview );
501 return( $SearchLine );
503 catch( Exception $e )
535 if( isset( $SearchLine[ 9 ] ) ===
false )
540 $Limitations = $this->Security->get_gp(
'search_output_limitations' ,
'string' ,
'' );
541 $Limitations = explode(
',' , $Limitations );
543 foreach( $SearchLine as $i => $Record )
545 $FetchId =
get_field( $Record ,
'fetch_id' );
547 $Limitations[ $FetchId ]++;
550 return( implode(
',' , $Limitations ) );
552 catch( Exception $e )
576 private function get_left_arrow()
582 $CurrentLimitations = $this->Security->get_gp(
'search_output_limitations' ,
'string' ,
'' );
583 if( $CurrentLimitations !=
'' )
585 $Arrows [] = $this->CachedMultyFS->get_template( __FILE__ ,
'search_form_prev_arrow.tpl' );;
590 catch( Exception $e )
618 private function get_right_arrow( $NextLimitations )
622 $SearchString = $this->Security->get_gp(
'search_string' ,
'string' );
623 $Page = $this->Security->get_gp(
'page' ,
'integer' , 0 ) + 1;
624 $Code = $this->CachedMultyFS->get_template( __FILE__ ,
'search_form_next_arrow.tpl' );
626 array(
'{search_string}' ,
'{next_limitations}' ,
'{page}' ) ,
627 array( $SearchString , $NextLimitations , $Page ) , $Code
632 catch( Exception $e )
664 $Arrows = $this->get_left_arrow();
667 if( $NextLimitations !=
'' )
669 $Arrows [] = $this->get_right_arrow( $NextLimitations );
672 $Code = $this->CachedMultyFS->get_template( __FILE__ ,
'search_form_controller.tpl' );
673 $Code = str_replace(
'{arrows}' , implode(
' ' , $Arrows ) , $Code );
677 catch( Exception $e )
707 foreach( $SearchLine as $i => $Result )
709 $TemplatePath = dirname( __FILE__ ).
'/res/templates/search_item.tpl';
710 $this->Output .= $this->CachedMultyFS->file_get_contents( $TemplatePath );
712 $this->Output = $this->String->print_record( $this->Output , $Result );
713 $this->Output = str_replace(
715 $this->Security->get_gp(
'page' ,
'integer' , 0 ) * 10 + $i + 1 ,
$this->Output
721 catch( Exception $e )
747 $SearchString = $this->Security->get_gp(
'search_string' ,
'string' ,
false );
749 if( $SearchString !==
false )
751 $Records = $this->
get_records( $Packages , $SearchString );
764 catch( Exception $e )
796 $ContextSet =
get_package(
'gui::context_set' ,
'last' , __FILE__ );
798 $ContextSet->add_context( dirname( __FILE__ ).
'/conf/cfcx_search_form' );
799 $ContextSet->add_context( dirname( __FILE__ ).
'/conf/cfcx_search_results' );
801 if( $ContextSet->execute( $Options , $this , __FILE__ ) )
return( $this->Output );
803 return( $this->Output );
805 catch( Exception $e )
837 $QueryString =
'1 = 1';
839 $SearchString = $this->Security->get_gp(
'search_string' ,
'string' ,
'' );
841 if( $SearchString !==
'' && isset( $Fields[ 0 ] ) )
843 $QueryString =
'( '.$Fields[ 0 ].
" LIKE '%".$SearchString.
"%'";
845 for( $i = 1 ; $i < count( $Fields ) ; $i++ )
847 $QueryString .=
' OR '.$Fields[ $i ].
" LIKE '%".$SearchString.
"%'";
850 $QueryString .=
' )';
853 return( $QueryString );
855 catch( Exception $e )