<?php
/*
 * Copyright 2005 Randy Smith <perlstalker@gmail.com>
 * $Id: api.php,v 1.5 2005/10/06 19:41:58 randy Exp $
 */

if (!defined ('SM_PATH')) { define ('SM_PATH','../../'); }
include_once(SM_PATH.'plugins/web_search/web_search.conf.php');
global $engine, $adsense;

function mini_search() {
  $search_phrase = _("Search the Web");

  include(SM_PATH.'plugins/web_search/web_search.conf.php');
  //global $engine;

  if ($engine == 'google') { mini_google($search_phrase); }
  else if ($engine == 'google-adsense') { mini_adsense($search_phrase); }
  else if ($engine == 'yahoo') { mini_yahoo($search_phrase); }
  else {
    if (file_exists(SM_PATH."plugins/web_search/$engine_mini.inc.php")) {
      include(SM_PATH."plugins/web_search/$engine_mini.inc.php");
    }
  }
}

function mini_google ($search_phrase) {
  include(SM_PATH.'plugins/web_search/web_search.conf.php');

  echo "<center>";
  printf ("<form method='get' action='http://www.google.com/search' target='%s' accept-charset='UTF-8'>",
	  (isset($results_in_new) && $results_in_new)? '_blank' : 'right'
	  );
  echo '<input name="q" maxlength="255"></input>';
  printf ('<input type="submit" name="btnG" value="%s" />', $search_phrase);
  printf ('<input type="hidden" name="hl" value="%s"></input>',
	  $google['hl']);
  printf ('<input type="hidden" name="ie" value="%s"></input>',
	  $google['ie']);
  printf ('<input type="hidden" name="oe" value="%s"></input>',
	  $google['oe']);

  echo "</form>";
  echo "</center>";
}

function mini_adsense ($search_phrase) {
  include(SM_PATH.'plugins/web_search/web_search.conf.php');

  echo "<center>";
  printf ("<form method='get' action='http://www.google.com/custom' name='searchweb' target='%s' accept-charset='UTF-8'>",
	  (isset($results_in_new) && $results_in_new)? '_blank' : 'right'
	  );
  echo '<input name="q" maxlength="255"></input>';
  printf ('<input type="submit" name="sa" value="%s"></input>', $search_phrase);
  printf ('<input type="hidden" name="client" value="%s"></input>',
	  $adsense['client']);
  printf ('<input type="hidden" name="channel" value="%s"></input>',
	  $adsense['channel']);
  printf ('<input type="hidden" name="forid" value="%s"></input>',
	  $adsense['forid']);
  printf ('<input type="hidden" name="ie" value="%s"></input>',
	  $adsense['ie']);
  printf ('<input type="hidden" name="oe" value="%s"></input>',
	  $adsense['oe']);
  printf ('<input type="hidden" name="cof" value="GALT:%s;GL:%s;DIV:%s;VLC:%s;AH:%s;BGC:%s;LBGC:%s;ALC:%s;LC:%s;T:%s;GFNT:%s;GIMP:%s;LH:%s;LW:%s;L:%s;S:%s;LP:%s;FORID:%s;"></input>',
	  $adsense['galt'],
	  $adsense['gl'],
	  $adsense['div'],
	  $adsense['vlc'],
	  $adsense['ah'],
	  $adsense['bgc'],
	  $adsense['lbgc'],
	  $adsense['alc'],
	  $adsense['lc'],
	  $adsense['t'],
	  $adsense['gfnt'],
	  $adsense['gimp'],
	  $adsense['lh'],
	  $adsense['lw'],
	  $adsense['l'],
	  $adsense['s'],
	  $adsense['lp'],
	  $adsense['forid']
	  );
  printf ('<input type="hidden" name="hl" value="%s"></input>',
	  $adsense['hl']);
  echo "</form>";
  echo "</center>";
}

function mini_yahoo ($search_phrase) {
  include(SM_PATH.'plugins/web_search/web_search.conf.php');

  echo "<center>";
  printf ("<form method='get' action='http://search.yahoo.com/search' target='%s' accept-charset='UTF-8'>",
	  (isset($results_in_new) && $results_in_new)? '_blank' : 'right'
	  );
  echo '<input name="p" maxlength="255"></input>';
  printf ('<input type="submit" name="prssweb" value="%s" />', $search_phrase);
  printf ('<input type="hidden" name="ei" value="%s"></input>',
	  $yahoo['ei']);
  echo "</form>";
  echo "</center>";
}

?>