<?php if (!defined('PmWiki')) exit();
/*******************************************************************
  file googlecse.php for PmWiki 2.

  Copyright 2007 Jon Haupt.
  This file is distributed under the terms of the GNU General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  Google Custom Search Engines
  This recipe allows you to place a Google Custom Search Engine
  (http://google.com/coop/cse/) into your wiki.  There are 8
  different arguments for the markup, which is (:googlecse:). 
  
  api : your google API.
  cse : you have to have created this cse before--this is its code.
  synd : ads or not.   defaults to open.
  w : width
  h : height
  title : title displayed at the top
  border : 
  output : js = javascript?

********************************************************************/
# Version date
$RecipeInfo['GoogleCSE']['Version'] = '2007-02-24';

#Define Google Custom Search Engine markup
Markup('googlecse', 'inline',  '/\\(:googlecse (.*?):\\)/e', 'GoogleCSE("$1")');

function GoogleCSE($opts) {
  // Defaults
  $defaults = array (
    'api' => '',    # google API
    'cse' => '',    # custom search engine code
    'synd' => 'open',   # syndication.  I think this is for google ads
    'w' => '320',   # width
    'h' => '75',   # height
    'title' => 'Google Custom Search',  # title of google CSE
    'border' => '', # borders...
    'output' => 'js');   # javascript
  $args = array_merge($defaults, ParseArgs($opts));

  // Begin output
  $output = "<div class='googlecse'><script src='http://gmodules.com/ig/ifr?url=http://google.com/coop/api/".$args['api'];
  $output .= "/cse/".$args['cse']."/gadget&amp;synd=".$args['synd']."&amp;w=".$args['w'];
  $output .= "&amp;h=".$args['h']."&amp;title=".$args['title']."&amp;border=".$args['border'];
  $output .= "&amp;output=".$args['output']."'></script><noscript>Google Custom Search Engine</noscript></div>";

  // Finish output and return it
  return Keep($output);
};