public_html/wp-content/plugins/wp-statistics/includes/functions/functions.php
// This function will return the SQL WHERE clause for getting the search words for a given search engine.
This function will return the SQL WHERE clause for getting the search words for a given search engine.
This function will return the SQL WHERE clause for getting the search words for a given search engine .
function wp_statistics_searchword_query( $search_engine = 'all' ) {
		GLOBAL $WP_Statistics;
		$searchengine_list = wp_statistics_searchengine_list();
		$search_query = '';
		if( $WP_Statistics->get_option( 'search_converted' ) ) {
						if( strtolower( $search_engine ) == 'all' ) {
				foreach( $searchengine_list as $key => $se ) {
					$search_query .= "( `engine` = '{$key}' AND `words` <> '' ) OR ";
				}
				$search_query = substr( $search_query, 0, strlen( $search_query ) - 4 );
			} else {
				$search_query .= "`engine` = '{$search_engine}' AND `words` <> ''";
			}
		} else {
						if( strtolower( $search_engine ) == 'all' ) {
				foreach( $searchengine_list as $se ) {
					if( is_array( $se['sqlpattern'] ) ) {
						foreach( $se['sqlpattern'] as $subse ) {
							$search_query .= "(`referred` LIKE '{$subse}{$se['querykey']}=%' AND `referred` NOT LIKE '{$subse}{$se['querykey']}=&%' AND `referred` NOT LIKE '{$subse}{$se['querykey']}=') OR ";
						}
					} else {
						$search_query .= "(`referred` LIKE '{$se['sqlpattern']}{$se['querykey']}=%' AND `referred` NOT LIKE '{$se['sqlpattern']}{$se['querykey']}=&%' AND `referred` NOT LIKE '{$se['sqlpattern']}{$se['querykey']}=')  OR ";
					}
				}
				$search_query = substr( $search_query, 0, strlen( $search_query ) - 4 );
			} else {
				if( is_array( $searchengine_list[$search_engine]['sqlpattern'] ) ) {
					foreach( $searchengine_list[$search_engine]['sqlpattern'] as $se ) {
						$search_query .= "(`referred` LIKE '{$se}{$searchengine_list[$search_engine]['querykey']}=%' AND `referred` NOT LIKE '{$se}{$searchengine_list[$search_engine]['querykey']}=&%' AND `referred` NOT LIKE '{$se}{$searchengine_list[$search_engine]['querykey']}=') OR ";
					}
					$search_query = substr( $search_query, 0, strlen( $search_query ) - 4 );
				} else {
					$search_query .= "(`referred` LIKE '{$searchengine_list[$search_engine]['sqlpattern']}{$searchengine_list[$search_engine]['querykey']}=%' AND `referred` NOT LIKE '{$searchengine_list[$search_engine]['sqlpattern']}{$searchengine_list[$search_engine]['querykey']}=&%' AND `referred` NOT LIKE '{$searchengine_list[$search_engine]['sqlpattern']}{$searchengine_list[$search_engine]['querykey']}=')";
				}
			}
		}
		return $search_query;
	}
function wp_statistics_searchword_query ( $ search_engine = 'all' ) { GLOBAL $ WP_Statistics ; $ searchengine_list = wp_statistics_searchengine_list ( ) ; $ search_query = '' ; if ( $ WP_Statistics -> get_option ( 'search_converted' ) ) { if ( strtolower ( $ search_engine ) == 'all' ) { foreach ( $ searchengine_list as $ key => $ se ) { $ search_query .= " ( `engine` = ' { $ key } ' AND `words` <> '' ) OR  " ; } $ search_query = substr ( $ search_query , 0 , strlen ( $ search_query ) - 4 ) ; } else { $ search_query .= " `engine` = ' { $ search_engine } ' AND `words` <> '' " ; } } else { if ( strtolower ( $ search_engine ) == 'all' ) { foreach ( $ searchengine_list as $ se ) { if ( is_array ( $ se [ 'sqlpattern' ] ) ) { foreach ( $ se [ 'sqlpattern' ] as $ subse ) { $ search_query .= " (`referred` LIKE ' { $ subse } { $ se [ 'querykey' ] } =%' AND `referred` NOT LIKE ' { $ subse } { $ se [ 'querykey' ] } =&%' AND `referred` NOT LIKE ' { $ subse } { $ se [ 'querykey' ] } =') OR  " ; } } else { $ search_query .= " (`referred` LIKE ' { $ se [ 'sqlpattern' ] } { $ se [ 'querykey' ] } =%' AND `referred` NOT LIKE ' { $ se [ 'sqlpattern' ] } { $ se [ 'querykey' ] } =&%' AND `referred` NOT LIKE ' { $ se [ 'sqlpattern' ] } { $ se [ 'querykey' ] } =')  OR  " ; } } $ search_query = substr ( $ search_query , 0 , strlen ( $ search_query ) - 4 ) ; } else { if ( is_array ( $ searchengine_list [ $ search_engine ] [ 'sqlpattern' ] ) ) { foreach ( $ searchengine_list [ $ search_engine ] [ 'sqlpattern' ] as $ se ) { $ search_query .= " (`referred` LIKE ' { $ se } { $ searchengine_list [ $ search_engine ] [ 'querykey' ] } =%' AND `referred` NOT LIKE ' { $ se } { $ searchengine_list [ $ search_engine ] [ 'querykey' ] } =&%' AND `referred` NOT LIKE ' { $ se } { $ searchengine_list [ $ search_engine ] [ 'querykey' ] } =') OR  " ; } $ search_query = substr ( $ search_query , 0 , strlen ( $ search_query ) - 4 ) ; } else { $ search_query .= " (`referred` LIKE ' { $ searchengine_list [ $ search_engine ] [ 'sqlpattern' ] } { $ searchengine_list [ $ search_engine ] [ 'querykey' ] } =%' AND `referred` NOT LIKE ' { $ searchengine_list [ $ search_engine ] [ 'sqlpattern' ] } { $ searchengine_list [ $ search_engine ] [ 'querykey' ] } =&%' AND `referred` NOT LIKE ' { $ searchengine_list [ $ search_engine ] [ 'sqlpattern' ] } { $ searchengine_list [ $ search_engine ] [ 'querykey' ] } =') " ; } } } return $ search_query ; }
This function will return the SQL WHERE clause for getting the search words for a given search engine.
This function will return the SQL WHERE clause for getting the search words for a given search engine .
// Get a complete list of search engines // Are we getting results for all search engines or a specific one?
 // For all of them?  Ok, look through the search engine list and create a SQL query string to get them all from the database. // Trim off the last ' OR ' for the loop above. // Are we getting results for all search engines or a specific one?
 // For all of them?  Ok, look through the search engine list and create a SQL query string to get them all from the database. // NOTE:  This SQL query can be *VERY* long. // The SQL pattern for a search engine may be an array if it has to handle multiple domains (like google.com and google.ca) or other factors. // Trim off the last ' OR ' for the loop above. // For just one?  Ok, the SQL pattern for a search engine may be an array if it has to handle multiple domains (like google.com and google.ca) or other factors. // Trim off the last ' OR ' for the loop above.