##############################################################
## MOD Title: Google Integrated Search
## MOD Author: pentapenguin < pentapenguin@bluebottle.com > (n/a) http://www.pentapenguin.com
## Traduccion Nazcar <nazcar@almogavers.net>
## MOD Description: Este Mod usa el Api de Google para hacer busquedas de tu web.
## MOD Version: 0.1.0
##
## Nivel de Instalacion: Facil
## Tiempo de Instalacion:  5 Minutos
## Ficheros a editar: 3
## search.php
## language/lang_english/lang_main.php
## templates/subSilver/search_body.tpl
##
## Ficheros Incluidos: 2
## templates/subSilver/google_search_results.tpl
## includes/nusoap.php
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MODs not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/
##############################################################
## Author Notes:
## Support for this MOD may be found at http://www.phpbb.com/phpBB/viewtopic.php?t=282881 or at 
## http://www.pentapenguin.com/forum/viewtopic.php?t=633
##
## This MOD is EasyMOD friendly! (http://area51.phpbb.com/phpBB/viewtopic.php?sid=&f=17&t=15391)
##
## Paso Opcional: Si tienes instalado el  eXtreme Styles MOD (http://www.phpbb.com/phpBB/viewtopic.php?t=125251), 
## Puedes copiar el
contrib/admin/xs_google_integrated_search.cfg a admin/xs_google_integrated_search.cfg y seras
## Notificado Automaticamente de actualizacion del mod cuando uses la Busqueda de actualizaciones del mod.
##
## NOTA IMPORTANTE: Para el funcionamiento del Mod primero ***DEBES OBTENER*** una licencia Gratuita de Google en http://www.google.com/apis/
## Cuando la Tengas debes de ponerla en el fichero search.php.
## Busca esta linea $google_key = ''; Y aade la licencia entre los ' '
##
## This MOD is bundled with NuSOAP. 
## For more information, see http://dietrich.ganx4.com/nusoap/ or http://sourceforge.net/projects/nusoap/
##
## Recommended additional MOD: I suggest you use the Guest Sessions MOD to help the Google bot index your 
## forum more easily. It may be found here: http://www.phpbbstyles.com/viewtopic.php?t=357
##
## Additional style support is included for the Aphrodite style.
## For full directions, see styles/style_aphrodite.txt
##############################################################
## MOD History:
##
##   2005-04-18 - Version 0.1.0
##      - First Public Beta
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################


#
#-----[ COPY ]------------------------------------------
#
copy templates/subSilver/google_search_results.tpl to templates/subSilver/google_search_results.tpl
copy includes/nusoap.php to includes/nusoap.php


#
#-----[ OPEN ]------------------------------------------ 
#
search.php


#
#-----[ FIND ]------------------------------------------
#
	else
	{
		username_search('');
	}

	exit;
}


#
#-----[ AFTER, ADD ]------------------------------------------
#

// Begin Google Integrated Search
else if ( $mode == 'google' && $search_keywords != '' )
{
	// Add your Google license key within the quotes below!!!!
	$google_key = '';
	// Add your Google license key within the quotes above!!!!

	// Don't modify anything below this unless you know what you're doing
	if ( $google_key == '' )
	{
		message_die(GENERAL_ERROR, 'You must enter your Google license key in search.php!');
	}

	$search_keywords = stripslashes(urldecode($search_keywords));
	$search_where = ( isset($HTTP_POST_VARS['search_where']) ) ? htmlspecialchars($HTTP_POST_VARS['search_where']) : htmlspecialchars($HTTP_GET_VARS['search_where']);
	$google_query = ( $search_where == 'site' ) ? $search_keywords . ' site:' . $board_config['server_name'] . $board_config['script_path'] : $search_keywords;
	$results_per_page = 10;
	
	// Include the NuSOAP class
	include($phpbb_root_path . 'includes/nusoap.' . $phpEx);
	
	// Initialize the SOAPclient
	$soapclient = new soapclient('http://api.google.com/search/beta2');
	
	// This array is various parameters passed to Google
	$params = array(
		'Googlekey' => $google_key,
		'q'   => $google_query,
		'start' => $start,
		'maxResults' => $results_per_page,
		'filter' => true,
		'restrict' => '',
		'safeSearch' => true,
		'lr' => '',
		'ie' => '',
		'oe' => '',
	);
	
	// Perform the search
	$search_results = $soapclient->call('doGoogleSearch', $params, 'urn:GoogleSearch', 'urn:GoogleSearch');

	// Did we get an error?
	if ( !empty($search_results['faultstring']) )
	{
		message_die(GENERAL_ERROR, 'The Google search failed: <br />' . $search_results['faultstring']);
	}
	
	$total_results = $search_results['estimatedTotalResultsCount'];
	$max_pages = ( $total_results >= 1000 ) ? 1000 : $total_results;
	$pagination = generate_pagination(append_sid("search.$phpEx?mode=google&amp;search_keywords=" . urlencode($search_keywords) . "&amp;search_where=$search_where"), $max_pages, $results_per_page, $start);

	// Were any results found?
	if ( !is_array($search_results['resultElements']) )
	{
		message_die(GENERAL_MESSAGE, $lang['No_google_results']);
	}
	
	foreach ($search_results['resultElements'] as $result)
	{
	$url = preg_replace('#(\?|&)sid=[a-z0-9]{32}#', '', $result['URL']);
	$url = ( strstr($url, $board_config['server_name']) ) ? append_sid($url) : $url;
	$target = ( strstr($url, $board_config['server_name']) ) ? '' : 'target="_blank"';
	
		$template->assign_block_vars('google_results_loop', array(
			'URL' => $url,
			'TITLE' => $result['title'],
			'SNIPPET' => $result['snippet'],
			'TARGET' => $target,
		));
	}	
	
	//
	// Output the basic page
	//
	$page_title = $lang['Google_search'];
	include($phpbb_root_path . 'includes/page_header.'.$phpEx);

	$template->set_filenames(array(
		'body' => 'google_search_results.tpl')
	);
	
	make_jumpbox('viewforum.'.$phpEx);
	
	$search_time = $search_results['searchTime'];
	$l_search_matches = ( $total_results == 1 ) ? sprintf($lang['Found_google_match'], $total_results, $search_time) : sprintf($lang['Found_google_matches'], $total_results, $search_time);
	
	$template->assign_vars(array(
		'L_SEARCH_MATCHES' => $l_search_matches,
		'PAGINATION' => $pagination,
		'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $results_per_page ) + 1 ), ceil( $max_pages / $results_per_page ) ),
	));

	$template->pparse('body');

	include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
	exit();
}
// End Google Integrated Search


#
#-----[ FIND ]------------------------------------------
#
$template->set_filenames(array(
	'body' => 'search_body.tpl')
);
make_jumpbox('viewforum.'.$phpEx);

$template->assign_vars(array(


#
#-----[ AFTER, ADD ]------------------------------------------
#
	
	// Begin Google Integrated Search
	'S_GOOGLE_SEARCH_ACTION' => append_sid("search.$phpEx"),
	'L_GOOGLE_SEARCH' => $lang['Google_search'],
	'L_GOOGLE_SEARCH_EXPLAIN' => $lang['Google_search_explain'],
	'L_SEARCH_SITE_ONLY' => $lang['Search_site_only'],
	'L_SEARCH_WEB' => $lang['Search_web'],
	// End Google Integrated Search


# 
#-----[ OPEN ]------------------------------------------ 
#
language/lang_english/lang_main.php


#
#-----[ FIND ]------------------------------------------
#
# Note: full line to find is $lang['Close_window'] = 'Close Window';
#
$lang['Close_window']


#
#-----[ AFTER, ADD ]------------------------------------------
#

// Begin Google Integrated Search
$lang['Google_search'] = 'Google Search';
$lang['Google_search_explain'] = 'Search our site using Google (<a href="http://www.google.com/help/basics.html" target="_blank">Tips</a>)';
$lang['Search_site_only'] = ' Search site only';
$lang['Search_web'] = 'Search web';
$lang['No_google_results'] = 'No results were found by Google. Please try again.';
$lang['Found_google_match'] = 'Search found %d match in %f seconds'; // eg. Search found 1 match in 0.5 seconds
$lang['Found_google_matches'] = 'Search found %d matches in %f seconds'; // eg. Search found 24 matches in 0.5 seconds
// End Google Integrated Search


# 
#-----[ OPEN ]------------------------------------------ 
#
language/lang_spanish/lang_main.php


#
#-----[ FIND ]------------------------------------------
#
# Note: La busqueda completa es  $lang['Close_window'] = 'Cierra la Ventana';
#
$lang['Close_window']


#
#-----[ AFTER, ADD ]------------------------------------------
#

// Begin Google Integrated Search
$lang['Google_search'] = 'Busqueda de Google';
$lang['Google_search_explain'] = 'Busqueda en Google de nuestro sitio';
$lang['Search_site_only'] = ' Busqueda solo en la web #onanismo';
$lang['Search_web'] = 'Busqueda General';
$lang['No_google_results'] = 'No se han encontrado resultados. Prueba de nuevo.';
$lang['Found_google_match'] = 'La Busqueda ha encontrado %d coincidencias en  %f segundos'; // eg. Search found 1 match in 0.5 seconds
$lang['Found_google_matches'] = 'La Busqueda ha encontrado %d coincidencias en  %f segundos'; // eg. Search found 24 matches in 0.5 seconds
// End Google Integrated Search
# 
#-----[ OPEN ]------------------------------------------ 
#
templates/subSilver/search_body.tpl


#
#-----[ FIND ]------------------------------------------
#
	<tr> 
		<td class="catBottom" colspan="4" align="center" height="28">{S_HIDDEN_FIELDS}<input class="liteoption" type="submit" value="{L_SEARCH}" /></td>
	</tr>
</table>

<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
	<tr> 
		<td align="right" valign="middle"><span class="gensmall">{S_TIMEZONE}</span></td>
	</tr>
</table></form>


#
#-----[ REPLACE WITH ]------------------------------------------
#

	<tr> 
		<td class="catBottom" colspan="4" align="center" height="28">{S_HIDDEN_FIELDS}<input class="liteoption" type="submit" value="{L_SEARCH}" /></td>
	</tr>
</table>
</form>

<br /><br />

<!-- Start Google Integrated Search MOD by http://www.pentapenguin.com -->
<form action="{S_GOOGLE_SEARCH_ACTION}" method="get">
<input type="hidden" name="mode" value="google" />

<table class="forumline" width="100%" cellpadding="4" cellspacing="1" border="0">
	<tr> 
		<th class="thHead" colspan="2" height="25">{L_GOOGLE_SEARCH}</th>
	</tr>
	<tr>
		<td class="row1"><span class="gen">{L_GOOGLE_SEARCH_EXPLAIN}</span></td>
		<td class="row2">
			<span class="gen">
			<input type="text" style="width: 300px" class="post" name="search_keywords" size="30" /><br />
			<input type="radio" name="search_where" value="site" checked="checked" /> {L_SEARCH_SITE_ONLY}<br />
			<input type="radio" name="search_where" value="web" /> {L_SEARCH_WEB}<br />
			</span>
		</td>
	</tr>
	<tr> 
		<td class="catBottom" colspan="2" align="center" height="28"><input class="liteoption" type="submit" value="{L_SEARCH}" /></td>
	</tr>
</table>
</form>
<!-- Finish Google Integrated Search MOD -->

<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
	<tr> 
		<td align="right" valign="middle"><span class="gensmall">{S_TIMEZONE}</span></td>
	</tr>
</table>


#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM 