Index: modules/gallery/contrib/g2_filter/g2_filter.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/gallery/contrib/g2_filter/g2_filter.module,v
retrieving revision 1.1
diff -u -r1.1 g2_filter.module
--- modules/gallery/contrib/g2_filter/g2_filter.module	9 Dec 2005 16:25:59 -0000	1.1
+++ modules/gallery/contrib/g2_filter/g2_filter.module	13 Dec 2005 04:47:53 -0000
@@ -1,440 +1,401 @@
-<?php
-// $Id: g2_filter.module,v 1.1 2005/12/09 16:25:59 walkah Exp $
-
-/**
- * @file
- * Allows adding gallery blocks into nodes using a filter --> [G2:item_id]
- *
- */
-
-/******************************* Help sections ************************************/
-
-function g2_filter_short_tip_translated() {
-  return t('You may link to G2 items on this site <a href="%explanation-url">using a special syntax</a>',
-    array('%explanation-url' => url('filter/tips', NULL, 'filter-g2_filter-0')));
-}
-
-function g2_filter_long_tip_translated() {
-  $prefix = variable_get("g2_filter_prefix", "G2");
-
-$output = "";
-$output .= '<strong>G2 Filter:</strong><p>You can link to items in your ';
-$output .= 'embedded Gallery 2 using a special code. ';
-$output .= 'This code will be replaced by a thumbnail image that is ';
-$output .= 'linked to the actual item in your Gallery. ';
-$output .= '<em>Syntax:</em><br />';
-$output .= '<blockquote><code>';
-$output .= '['.$prefix.':<em>item_id</em> n=<em>number</em> type=<em>type</em> size=<em>number</em> class=<em>name</em> frame=<em>name</em> album_frame=<em>name</em> item_frame=<em>name</em>]';
-$output .= '</code></blockquote>';
-
-$output .= '<ul><li>item_id (required): This is the item ID from G2. ';
-$output .= 'If you look at the URL of the item, this is the last number.  '
-			.'<em>Note that if the item_id is a single photo, n must be 1</em></li> ';
-
-$output .= '<li>n (suggested): This is the number of photos you want the block to show. ';
-$output .= 'It will override whatever is set in the defaults (initially 1). '
-			.' Note: this will change past instances where you did not set n -- the reason for its suggested use.</li> ';
-
-$output .= '<li>type: The default type of gallery block. Any of the following may be used: ';
-$output .= '<em>randomImage, recentImage, viewedImage, randomAlbum, recentAlbum, viewedAlbum, dailyImage, ' 
-			.'weeklyImage, monthlyImage, dailyAlbum, weeklyAlbum, monthlyAlbum, specificItem . </em> '
-			.'Note that for n=1, selectedItem is automatically chosen regardless of this parameter.</li> ';
-
-$output .= '<li>class: The block that G2 returns is wrapped in a DIV so additional styling can be done. ';
-$output .= 'The classes for this DIV are located in g2_filter.css.  Included with the module ';
-$output .= 'are "left", "right", and "nowrap". These position the image block to the left or ';
-$output .= 'right or on a line all its own with the text not wrapping. You can also add your '; 
-$output .= 'own class(es) to the CSS file and they will automatically be available.</li> ';
-
-$output .= '<li>size: The length of the longest side for the thumbnail. ';
-$output .= 'The other side is determined automatically to keep the same aspect ratio.</li> ';
-
-$output .= '<li>frame/album_frame/item_frame: You can use just "frame" to assign a frame ';
-$output .= 'to the thumbnail regardless of whether it\'s for an album or a single item. ';
-$output .= 'Using aframe will only affect albums and iframe will only affect single items. ';
-$output .= 'Frames included with the default Gallery 2 install are: ';
-$output .= 'bamboo, book, brand , dots, flicking, gold, gold2, polaroid, polaroids, shadow, ';
-$output .= 'shells, slide, solid, notebook, wood.</li>';
-
-return t($output);
-
-}
-
-function g2_filter_help($section = 'admin/help#image_filter') {
-  $output = '';
-  switch ($section) {
-    case 'admin/help#g2_filter':
-      $output = t('<p>Used to add image blocks from your embedded Gallery 2 to a node 
-			like a blog entry or a story. To enable this feature and learn the proper syntax, 
-			visit the <a href="%filters">filters configuration screen</a>.</p>', 
-			array('%filters' => url('admin/filters')));
-      
-			break;
-    case 'admin/modules#description':
-      $output = t("Allow users to reference G2 items from nodes.");
-      break;
-    case 'filter#short-tip':
-      return g2_filter_short_tip_translated();
-    case 'filter#long-tip':
-      return g2_filter_long_tip_translated();
-  }
-
-  return $output;
-}
-
-
-/******************************* Configuration ************************************/
-
-function g2_filter_get_settings_form() {
-  $typeMap = array('randomImage' => t('Random image'),
-		   'recentImage' => t('Recent image'),
-		   'viewedImage' => t('Viewed image'),
-		   'randomAlbum' => t('Random album'),
-		   'recentAlbum' => t('Recent album'),
-		   'viewedAlbum' => t('Viewed album'),
-		   'dailyImage' => t('Daily image'),
-		   'weeklyImage' => t('Weekly image'),
-		   'monthlyImage' => t('Monthly image'),
-		   'dailyAlbum' => t('Daily album'),
-		   'weeklyAlbum' => t('Weekly album'),
-		   'monthlyAlbum' => t('Monthly album')); 
-//we don't include specificItem, since it can be selected automatically if n=1
-		   
-  $output .= form_textfield(t("Filter prefix"), "g2_filter_prefix",
-             variable_get("g2_filter_prefix", "G2"), 10, 10,
-             t("Prefix to use with filter. Example: 'G2' means you use [G2: 999]."));  
-             
-  $output .= form_select(t('Image Block Type'), 'g2_filter_default_block_type',
-			  variable_get('g2_filter_default_block_type', 'viewedImage'), $typeMap,
-			  t('Pick default type of image block you\'d like to use, default is Recent image. Viewed image is by most clicks.'));         
-			  
-  $output .= form_textfield(t("Default Number of Images"), "g2_filter_n_images",
-             variable_get("g2_filter_n_images", 1), 3, 3,
-             t("How many images you want the default block to show.  Best to keep at 1 and use the n parameter."));  
-//////*********in fact, should we remove this option all together?  because the way it is now, if you change this to n>1
-//then instances where n was not specified and item_id is a specific item, the block breaks and nothing is shown.
-
-  $output .= form_checkboxes(
-      t('Default Image Block Settings'),
-      'g2_filter_default_show',
-      variable_get('g2_filter_default_show', 'none'),
-      array('title' => 'Title (the caption)',
-	    'date' => 'Date',
-	    'views' => 'View Count',
-	    'owner' => 'Item owner',
-	    'heading' => 'Heading',
-	    'fullSize' => 'Full Size'),
-      t('Choose the item metadata you\'d like to display by default.  This will change all instances where show parameter was not specified.'));
-
-             
-  $output .= form_textfield(t("Default thumbnail size"), "g2_filter_default_size",
-             variable_get("g2_filter_default_size", "150"), 3, 3,
-             t('If no size is specified when calling the filter, this size will be used.  '
-             .'Note that the display size will be limited by the size of the item_id in Gallery.'));  
-
-  $output .= form_textfield(t("Default class"), "g2_filter_default_div_class",
-             variable_get("g2_filter_default_div_class", "nowrap"), 20, 20,
-             t("left, right, or nowrap. (See g2_filter.css to add more or modify these.)"));  
-
-  $output .= form_textfield(t("Default album frame"), "g2_filter_default_album_frame",
-             variable_get("g2_filter_default_album_frame", "none"), 20, 20,
-             t("Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your G2 install for a complete list. Use 'none' or blank for no frame. "));  
-
-  $output .= form_textfield(t("Default item frame"), "g2_filter_default_item_frame",
-             variable_get("g2_filter_default_item_frame", "none"), 20, 20,
-             t("Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your G2 install for a complete list. Use 'none' or blank for no frame. "));  
-
-	return $output;
-}
-
-// Hook which handles filtering.
-function g2_filter_filter($op, $delta = 0, $format = -1, $text = '') {
-  switch ($op) {
-    case 'list':
-      return array(0 => t('G2 filter'));
-    case 'description':
-      return t('Allow users to easily reference G2 items from nodes.');
-    case 'process':
-      return g2_filter_process($text);
-		case 'settings':
-		  $group = g2_filter_get_settings_form();
-      return form_group(t("Gallery 2 Filter"), $group);
-    default:
-      return $text;
-  }
-}
-
-function g2_filter_filter_tips($delta = 0, $format = -1, $long = false) {
-  if ($long) {
-    return g2_filter_long_tip_translated();
-  }
-  else {
-    return g2_filter_short_tip_translated();
-  }
-}
-
-// ***************** The Filter in Action ***********************
-
-define("G2_FILTER_WORD", 1);
-define("G2_FILTER_INTEGER", 2);
-define("G2_FILTER_STRING", 3);
-
-function g2_filter_attr_value($text, $value_type = G2_FILTER_WORD) {
-  // Strip off initial and final quotes.
-  $first = substr($text, 0, 1);
-  if ($first == "\"" || $first == "\'") {
-    if (substr($text, -1, 1) == $first) {
-      $text = substr($text, 1, -1);
-    }
-  }
-  switch ($value_type) {
-  case G2_FILTER_WORD:
-    return preg_replace("/\W/", '', $text);
-  case G2_FILTER_INTEGER:
-    return preg_replace("/\D/", '', $text);
-  default:
-    return check_plain($text);
-  }
-}
-
-// Execute filter on given text.
-function g2_filter_process($text) {
-
-  // Find all the image codes and loop over them, replacing each with the G2 image block
-  $prefix = variable_get("g2_filter_prefix", "G2");
-
-	$matchetxt = "/\[".trim($prefix).":(\d+)(\s*,)?\s*(.*?)\]/i";
-  preg_match_all($matchetxt, $text, $matches, PREG_SET_ORDER);
-
-  // If we have at least one match, set everything up
-  if (count($matches) > 0) { 
-    // Set the default and path variables based on module settings
-    $default_size        = variable_get("g2_filter_default_size", 150);
-    $default_div_class   = variable_get("g2_filter_default_div_class", "nowrap");
-    $default_album_frame = variable_get("g2_filter_default_album_frame", "");
-    $default_item_frame  = variable_get("g2_filter_default_item_frame", "");
-	$default_block_type  = variable_get('g2_filter_default_block_type', 'recentImage');
-	$default_n_images 	 = variable_get("g2_filter_n_images", 1);
-	$default_show 		 = variable_get('g2_filter_default_show', 'none');
-	
-		if ($default_album_frame == 'none') {
-		  $default_album_frame = '';
-	  }
-		if ($default_item_frame == 'none') {
-		  $default_item_frame = '';
-	  }		
-
-		// This will hold the list of frames used for images so we can add the CSS link(s) at the end
-		$frame_list = array() ;
-		
-/* this is all done by _gallery_init(true) function
-		// Set up the pathing
-    $relative_G2_Path  = variable_get("gallery_dir", "gallery2");
-    $embed_uri         = url('gallery');
-    $embed_php_path    = $relative_G2_Path . 'embed.php';
-    //the above line needs work, when the user sets the relative G2 path without a trailing / this module breaks
-  
-  // The tolerant base_url patch in http://drupal.org/node/32389 seems to work well, but not all of it is needed.
-  // The http or https part is not required.
-  // BUT, does this work for all cases (Apache, IIS?)
-  if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\,/')) {
-    $embedPath = "/$dir";
-  } else {
-    $embedPath = '/';
-  }
-
-    // Link to the embedding code
-		require_once($embed_php_path);
-
-		// Grab the user information from Drupal
-		global $user;
-*/
-		// This sets up the embedding
-   list ($success, $ret) = _gallery_init(true); 
-   	//_gallery_init() is from gallery.module, any reason not to use it? 
-	//just remember if they change that function this module breaks
-   if (!$success) {
-      gallery_error(t('Unable to initialize embedded Gallery'), $ret);
-      return;
-    } /*  since i commented this out, and use galler_init, i can probably get rid of some of the init code above
-		$ret = GalleryEmbed::init(array('embedUri' => $embed_uri,
-       'embedPath' => $embed_path,
-       'relativeG2Path' => $relative_G2_Path,
-       'loginRedirect' => '',
-       'fullInit' => true,
-       'activeUserId' => $user->uid)); */
-  }
-
-	foreach ($matches as $match) {
-
-    // Pull out the arguments into the $args array
-    $args = array();
-    preg_match_all("/(\w+)\=(\"[^\"]*\"|\S*)/", $match[3], $a, PREG_SET_ORDER);
-
-    foreach ($a as $arg) {
-      $args[strtolower($arg[1])] = $arg[2];
-    }
-
-		// Set number of images to show
-    $n_images = g2_filter_attr_value($args['n'], G2_FILTER_INTEGER);
-		if ($n_images == 0) {
-		  // No size specified; use the default
-			$n_images = $default_n_images;
-		}
-
-		// Set the block type
-    $block_type = g2_filter_attr_value($args['type'], G2_FILTER_WORD);
-		if (empty($block_type)) {
-		  // No size specified; use the default
-			$block_type = $default_block_type;
-		}
-		if ($n_images <= 1) $block_type = 'specificItem'; //so it shows something if n=1 and an album is selected
-		
-		// Set the size of the thumbnail
-    $size = g2_filter_attr_value($args['size'], G2_FILTER_INTEGER);
-		if ($size == 0) {
-		  // No size specified; use the default
-			$size = $default_size;
-		}
-
-		// Set the class of the div
-    $div_class = g2_filter_attr_value($args['class'], G2_FILTER_WORD);
-		if (empty($div_class)) {
-		  // No class specified; use the default
-			$div_class = $default_div_class;
-		}
-
-		// Set the overriding, album, and item frames
-    $frame       = g2_filter_attr_value($args['frame'], G2_FILTER_WORD);
-    $album_frame = g2_filter_attr_value($args['aframe'], G2_FILTER_WORD);
-    $item_frame  = g2_filter_attr_value($args['iframe'], G2_FILTER_WORD);
-
-		if (empty($frame)) {
-		  // No overriding frame given; check for album_frame and item_frame
-		  if (empty($album_frame)) {
-		    // No album frame specified; use the default one
-			  $album_frame = $default_album_frame;
-		  }
- 
-		  if (empty($item_frame)) {
-		    // No item frame specified; use the default one
-			  $item_frame = $default_item_frame;
-		  }
- 
-    } else {
-		  // Overriding frame given; use it
-			$album_frame = $frame;
-			$item_frame  = $frame;
-		}
-
-		// Add the requested frames to the array so we can get the CSS later. Don't worry about
-		// dupes at this point; they will be filtered out later.
-		array_push($frame_list,$frame);
-		array_push($frame_list,$album_frame);
-		array_push($frame_list,$item_frame);
-
-		// This part actually fetches the image block. It uses the same paramaters as the code
-		// found under "Image Block" in site admin in G2. Copied and slightly modified here for reference.
-
-    // blocks  	  Pipe(|) separate list chosen from: randomImage, recentImage, 
-		//            viewedImage, randomAlbum, recentAlbum, viewedAlbum, dailyImage, 
-		//            weeklyImage, monthlyImage, dailyAlbum, weeklyAlbum, monthlyAlbum, 
-		//            specificItem; default is randomImage
-    // show  	    Pipe(|) separated list chosen from: title, date, views, owner, heading, 
-		//            fullSize; the value can also be: none
-		//            NOTE: If you want your size to be bigger than the thumbnail size for that image as
-		//            defined in your G2, you must use 'show' => 'fullSize'
-    // itemId 	  Limit the item selection to the subtree of the gallery under the 
-		//            album with the given id; or the id of the item to display when used with 
-		//            specificItem block type
-    // maxSize 	  Scale images to this maximum size
-    // linkTarget Add a link target (for example, to open links in a new browser window)
-    // itemFrame  Image frame to use around images
-    // albumFrame Image frame to use around albums
-
-
-//$blocks = 'specificItem'; //not used 
-$show = $default_show;
-
-// Not customized yet:
-$link_target = '';  
-
-	
-///////keizo
-        // Allow for multiple image types
-        $param_blocks_array = array_fill(0,$n_images,$block_type);   
-        $params['itemId'] = $match[1];
-        $params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : ""; 
-        $param_show_array = $show;
-        $params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : ""; 
-        $params['maxSize'] = $size;
-        // Add frames and link target using g2_filter code from MichelleC
-        $params['albumFrame'] = $album_frame;
-        $params['itemFrame'] =  $item_frame;
-        $params['linkTarget'] =  $link_target;
-
-        $block = array();
-        list($ret, $imageBlockHtml) = GalleryEmbed::getImageBlock($params);
-        if ($ret->isError()) {
-          gallery_error(t('Unable to get Gallery image block'), $ret);
-          return;
-        } else {
-          //if ($imageBlockHtml) {  this line is redundant isn't it?
-			// Add a div around the table for styling
-			if ($div_class != 'none') {
-			  $imageBlockHtml = '<div class ="giImageBlock ' . $div_class . '">' .
-			  $imageBlockHtml . '</div>';
-			}	
-				// This puts the image block HTML back into the rest of the text
-			$text = str_replace($match[0], $imageBlockHtml, $text);
-          //}
-        }      
- //end keizo
-/*		list ($ret, $imageBlockHtml) = 
-		GalleryEmbed::getImageBlock(array(
-		'blocks' => $blocks, 
-		'show' => $show , 
-		'itemId' => $match[1], 
-		'maxSize' => $size, 
-		'linkTarget' => $link_target,
-		'albumFrame' => $album_frame, 
-		'itemFrame' => $item_frame));
-
-		// Add a div around the table for styling
-    $imageBlockHtml = '<div class ="' . $div_class . '">' . $imageBlockHtml . '</div>';
-
-		// This puts the image block HTML back into the rest of the text
-    $text = str_replace($match[0], $imageBlockHtml, $text);
-*/
-
-
-  } // end of for loop through matches
-
-	// If we had at least one match, finish up
-  if (count($matches) > 0) { 
-
-	  GalleryEmbed::done();
-
-    // Add the CSS link(s)
-    $css_links = '';
-
-	  // In order to use the album/image frames, we need to link to the style sheet(s)
-	  $frame_list = array_unique($frame_list);
-    foreach ($frame_list as $frame) {
-    $css_links .= '<link rel="stylesheet" href="' . $relative_G2_Path . 
-											'/main.php?g2_controller=imageblock.ExternalCSS&amp;g2_frames=' .$frame.'"/> ' ;
-    }
-
-		// Link to the CSS that controls the styling of the wrapping div
-		$div_css = drupal_get_path('module', 'g2_filter') . "/g2_filter.css";
-		$css_links .= '<link rel="stylesheet" href="' . $div_css . '"/> ' ;
-
-    $text = $css_links .= $text ;
-
-  }
-
-  return $text;
-}
-
-
-?>
+<?php
+
+
+// $Id: g2_filter.module,v 1.1 2005-12-09 16:25:59 walkah Exp $
+
+/**
+ * @file
+ * Allows adding gallery blocks into nodes using a filter --> [G2:item_id]
+ *
+ */
+
+/******************************* Help sections ************************************/
+
+function g2_filter_short_tip_translated() {
+	return t('You may link to G2 items on this site <a href="%explanation-url">using a special syntax</a>', array ('%explanation-url' => url('filter/tips', NULL, 'filter-g2_filter-0')));
+}
+
+function g2_filter_long_tip_translated() {
+	$prefix = variable_get("g2_filter_prefix", "G2");
+
+	$output = "";
+	$output .= '<strong>G2 Filter:</strong><p>You can link to items in your ';
+	$output .= 'embedded Gallery 2 using a special code. ';
+	$output .= 'This code will be replaced by a thumbnail image that is ';
+	$output .= 'linked to the actual item in your Gallery. ';
+	$output .= '<em>Syntax:</em><br />';
+	$output .= '<blockquote><code>';
+	$output .= '['.$prefix.':<em>item_id</em> n=<em>number</em> type=<em>type</em> size=<em>number</em> class=<em>name</em> frame=<em>name</em> album_frame=<em>name</em> item_frame=<em>name</em>]';
+	$output .= '</code></blockquote>';
+
+	$output .= '<ul><li>item_id (required): This is the item ID from G2. ';
+	$output .= 'If you look at the URL of the item, this is the last number.  '.'<em>Note that if the item_id is a single photo, n must be 1</em></li> ';
+
+	$output .= '<li>n (suggested): This is the number of photos you want the block to show. ';
+	$output .= 'It will override whatever is set in the defaults (initially 1). '.' Note: this will change past instances where you did not set n -- the reason for its suggested use.</li> ';
+
+	$output .= '<li>type: The default type of gallery block. Any of the following may be used: ';
+	$output .= '<em>randomImage, recentImage, viewedImage, randomAlbum, recentAlbum, viewedAlbum, dailyImage, '.'weeklyImage, monthlyImage, dailyAlbum, weeklyAlbum, monthlyAlbum, specificItem . </em> '.'Note that for n=1, selectedItem is automatically chosen regardless of this parameter.</li> ';
+
+	$output .= '<li>class: The block that G2 returns is wrapped in a DIV so additional styling can be done. ';
+	$output .= 'The classes for this DIV are located in g2_filter.css.  Included with the module ';
+	$output .= 'are "left", "right", and "nowrap". These position the image block to the left or ';
+	$output .= 'right or on a line all its own with the text not wrapping. You can also add your ';
+	$output .= 'own class(es) to the CSS file and they will automatically be available.</li> ';
+
+	$output .= '<li>size: The length of the longest side for the thumbnail. ';
+	$output .= 'The other side is determined automatically to keep the same aspect ratio.</li> ';
+
+	$output .= '<li>frame/album_frame/item_frame: You can use just "frame" to assign a frame ';
+	$output .= 'to the thumbnail regardless of whether it\'s for an album or a single item. ';
+	$output .= 'Using aframe will only affect albums and iframe will only affect single items. ';
+	$output .= 'Frames included with the default Gallery 2 install are: ';
+	$output .= 'bamboo, book, brand , dots, flicking, gold, gold2, polaroid, polaroids, shadow, ';
+	$output .= 'shells, slide, solid, notebook, wood.</li>';
+
+	return t($output);
+
+}
+
+function g2_filter_help($section = 'admin/help#image_filter') {
+	$output = '';
+	switch ($section) {
+		case 'admin/help#g2_filter' :
+			$output = t('<p>Used to add image blocks from your embedded Gallery 2 to a node
+			                        like a blog entry or a story. To enable this feature and learn the proper syntax,
+			                        visit the <a href="%filters">filters configuration screen</a>.</p>', array ('%filters' => url('admin/filters')));
+
+			break;
+		case 'admin/modules#description' :
+			$output = t("Allow users to reference G2 items from nodes.");
+			break;
+		case 'filter#short-tip' :
+			return g2_filter_short_tip_translated();
+		case 'filter#long-tip' :
+			return g2_filter_long_tip_translated();
+	}
+
+	return $output;
+}
+
+/******************************* Configuration ************************************/
+
+function g2_filter_settings() {
+  $typeMap = array('randomImage' => t('Random image'),
+           'recentImage' => t('Recent image'),
+           'viewedImage' => t('Viewed image'),
+           'randomAlbum' => t('Random album'),
+           'recentAlbum' => t('Recent album'),
+           'viewedAlbum' => t('Viewed album'),
+           'dailyImage' => t('Daily image'),
+           'weeklyImage' => t('Weekly image'),
+           'monthlyImage' => t('Monthly image'),
+           'dailyAlbum' => t('Daily album'),
+           'weeklyAlbum' => t('Weekly album'),
+           'monthlyAlbum' => t('Monthly album'));
+  $form = array(
+    '#title' => t('Gallery 2 Filter'),
+    '#type' => 'fieldset',
+    '#collapsible' => true,
+    '#collapsed' => false,
+  );
+//we don't include specificItem, since it can be selected automatically if n=1
+  $form['g2_filter_prefix'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Filter prefix'),
+    '#default_value' => variable_get('g2_filter_prefix', 'G2'),
+    '#size' => 10,
+    '#maxlength' => 10,
+    '#description' => t('Prefix to use with filter. Example: \'G2\' means you use [G2: 999].'),
+  );
+
+  $form['g2_filter_default_block_type'] = array(
+    '#type' => 'select',
+    '#title' => t('Image Block Type'),
+    '#default_value' => variable_get('g2_filter_default_block_type', 'viewedImage'),
+    '#options' => $typeMap,
+    '#description' => t('Pick default type of image block you\'d like to use, default is Recent image. Viewed image is by most clicks.'),
+  );
+  $form['g2_filter_n_images'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default Number of Images'),
+    '#default_value' => variable_get('g2_filter_n_images', 1),
+    '#size' => 3,
+    '#maxlength' => 3,
+    '#description' => t('How many images you want the default block to show.  Best to keep at 1 and use the n parameter.'),
+  );
+//////*********in fact, should we remove this option all together?  because the way it is now, if you change this to n>1
+//then instances where n was not specified and item_id is a specific item, the block breaks and nothing is shown.
+  $form['g2_filter_default_show'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Default Image Block Settings'),
+    '#default_value' => variable_get('g2_filter_default_show', array('none')),
+    '#options' => array('title' => 'Title (the caption)',
+        'date' => 'Date',
+        'views' => 'View Count',
+        'owner' => 'Item owner',
+        'heading' => 'Heading',
+        'fullSize' => 'Full Size'),
+    '#description' => t('Choose the item metadata you\'d like to display by default.  This will change all instances where show parameter was not specified.'),
+  );
+  $form['g2_filter_default_size'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default thumbnail size'),
+    '#default_value' => variable_get("g2_filter_default_size", "150"),
+    '#size' => 3,
+    '#maxlength' => 3,
+    '#description' => t('If no size is specified when calling the filter, this size will be used.  '
+               .'Note that the display size will be limited by the size of the item_id in Gallery.'),
+  );
+  $form['g2_filter_default_div_class'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default class'),
+    '#default_value' => variable_get('g2_filter_default_div_class', 'nowrap'),
+    '#size' => 20,
+    '#maxlength' => 20,
+    '#description' => t('left, right, or nowrap. (See g2_filter.css to add more or modify these.)'),
+  );
+  $form['g2_filter_default_album_frame'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default album frame'),
+    '#default_value' => variable_get('g2_filter_default_album_frame', 'none'),
+    '#size' => 20,
+    '#maxlength' => 20,
+    '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your G2 install for a complete list. Use \'none\' or blank for no frame. '),
+  );
+  $form['g2_filter_default_item_frame'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Default item frame'),
+    '#default_value' => variable_get('g2_filter_default_item_frame', 'none'),
+    '#size' => 20,
+    '#maxlength' => 20,
+    '#description' => t('Enter a frame name like notebook, polaroid, shadow, slide, wood, etc. See your G2 install for a complete list. Use \'none\' or blank for no frame.'),
+  );
+    return $form;
+}
+
+// Hook which handles filtering.
+function g2_filter_filter($op, $delta = 0, $format = -1, $text = '') {
+	switch ($op) {
+		case 'list' :
+			return array (0 => t('G2 filter'));
+		case 'description' :
+			return t('Allow users to easily reference G2 items from nodes.');
+		case 'process' :
+			return g2_filter_process($text);
+			/*        case 'settings':
+			          $group = g2_filter_get_settings_form();
+			      return form_group(t("Gallery 2 Filter"), $group);*/
+		default :
+			return $text;
+	}
+}
+
+function g2_filter_filter_tips($delta = 0, $format = -1, $long = false) {
+	if ($long) {
+		return g2_filter_long_tip_translated();
+	} else {
+		return g2_filter_short_tip_translated();
+	}
+}
+
+// ***************** The Filter in Action ***********************
+
+define('G2_FILTER_WORD', 1);
+define('G2_FILTER_INTEGER', 2);
+define('G2_FILTER_STRING', 3);
+
+function g2_filter_attr_value($text, $value_type = G2_FILTER_WORD) {
+		// Strip off initial and final quotes.
+	$first = substr($text, 0, 1);
+	if ($first == "\"" || $first == "\'") {
+		if (substr($text, -1, 1) == $first) {
+			$text = substr($text, 1, -1);
+		}
+	}
+	switch ($value_type) {
+		case G2_FILTER_WORD :
+			return preg_replace("/\W/", '', $text);
+		case G2_FILTER_INTEGER :
+			return preg_replace("/\D/", '', $text);
+		default :
+			return check_plain($text);
+	}
+}
+
+// Execute filter on given text.
+function g2_filter_process($text) {
+	// Find all the image codes and loop over them, replacing each with the G2 image block
+	$prefix = variable_get('g2_filter_prefix', 'G2');
+
+	$matchetxt = "/\[".trim($prefix).":(\d+)(\s*,)?\s*(.*?)\]/i";
+	preg_match_all($matchetxt, $text, $matches, PREG_SET_ORDER);
+	// If we have at least one match, set everything up
+	if (count($matches) > 0) {
+		// Set the default and path variables based on module settings
+		$default_size = variable_get('g2_filter_default_size', 150);
+		$default_div_class = variable_get('g2_filter_default_div_class', 'nowrap');
+		$default_album_frame = variable_get('g2_filter_default_album_frame', '');
+		$default_item_frame = variable_get('g2_filter_default_item_frame', '');
+		$default_block_type = variable_get('g2_filter_default_block_type', 'recentImage');
+		$default_n_images = variable_get('g2_filter_n_images', 1);
+		$default_show = variable_get('g2_filter_default_show', 'none');
+
+		if ($default_album_frame == 'none') {
+			$default_album_frame = '';
+		}
+		if ($default_item_frame == 'none') {
+			$default_item_frame = '';
+		}
+
+		// This will hold the list of frames used for images so we can add the CSS link(s) at the end
+		$frame_list = array ();
+
+		// This sets up the embedding
+		list ($success, $ret) = _gallery_init(true);
+		if (!$success) {
+			gallery_error(t('Unable to initialize embedded Gallery'), $ret);
+			return;
+		}
+	}
+	foreach ($matches as $match) {
+		// Pull out the arguments into the $args array
+		$args = array ();
+		preg_match_all("/(\w+)\=(\"[^\"]*\"|\S*)/", $match[3], $a, PREG_SET_ORDER);
+
+		foreach ($a as $arg) {
+			$args[strtolower($arg[1])] = $arg[2];
+		}
+
+		// Set number of images to show
+		$n_images = g2_filter_attr_value($args['n'], G2_FILTER_INTEGER);
+		if ($n_images == 0) {
+			// No size specified; use the default
+			$n_images = $default_n_images;
+		}
+
+		// Set the block type
+		$block_type = g2_filter_attr_value($args['type'], G2_FILTER_WORD);
+
+		if (empty ($block_type)) {
+			// No size specified; use the default
+			$block_type = $default_block_type;
+		}
+		if ($n_images <= 1)
+			$block_type = 'specificItem'; //so it shows something if n=1 and an album is selected
+
+		// Set the size of the thumbnail
+		$size = g2_filter_attr_value($args['size'], G2_FILTER_INTEGER);
+		if ($size == 0) {
+			// No size specified; use the default
+			$size = $default_size;
+		}
+
+		// Set the class of the div
+		$div_class = g2_filter_attr_value($args['class'], G2_FILTER_WORD);
+		if (empty ($div_class)) {
+			// No class specified; use the default
+			$div_class = $default_div_class;
+		}
+
+		// Set the overriding, album, and item frames
+		$frame = g2_filter_attr_value($args['frame'], G2_FILTER_WORD);
+		$album_frame = g2_filter_attr_value($args['aframe'], G2_FILTER_WORD);
+		$item_frame = g2_filter_attr_value($args['iframe'], G2_FILTER_WORD);
+
+		if (empty ($frame)) {
+			// No overriding frame given; check for album_frame and item_frame
+			if (empty ($album_frame)) {
+				// No album frame specified; use the default one
+				$album_frame = $default_album_frame;
+			}
+
+			if (empty ($item_frame)) {
+				// No item frame specified; use the default one
+				$item_frame = $default_item_frame;
+			}
+
+		} else {
+			// Overriding frame given; use it
+			$album_frame = $frame;
+			$item_frame = $frame;
+		}
+
+		// Add the requested frames to the array so we can get the CSS later. Don't worry about
+		// dupes at this point; they will be filtered out later.
+		array_push($frame_list, $frame);
+		array_push($frame_list, $album_frame);
+		array_push($frame_list, $item_frame);
+
+		// This part actually fetches the image block. It uses the same paramaters as the code
+		// found under "Image Block" in site admin in G2. Copied and slightly modified here for reference.
+
+		// blocks        Pipe(|) separate list chosen from: randomImage, recentImage,
+		//            viewedImage, randomAlbum, recentAlbum, viewedAlbum, dailyImage,
+		//            weeklyImage, monthlyImage, dailyAlbum, weeklyAlbum, monthlyAlbum,
+		//            specificItem; default is randomImage
+		// show          Pipe(|) separated list chosen from: title, date, views, owner, heading,
+		//            fullSize; the value can also be: none
+		//            NOTE: If you want your size to be bigger than the thumbnail size for that image as
+		//            defined in your G2, you must use 'show' => 'fullSize'
+		// itemId       Limit the item selection to the subtree of the gallery under the
+		//            album with the given id; or the id of the item to display when used with
+		//            specificItem block type
+		// maxSize       Scale images to this maximum size
+		// linkTarget Add a link target (for example, to open links in a new browser window)
+		// itemFrame  Image frame to use around images
+		// albumFrame Image frame to use around albums
+
+		//$blocks = 'specificItem'; //not used
+		$show = $default_show;
+
+		// Not customized yet:
+		$link_target = '';
+
+		$param_blocks_array = array_fill(0, $n_images, $block_type);
+		$params['itemId'] = $match[1];
+		$params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : "";
+		$param_show_array = $show;
+		$params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : "";
+		$params['maxSize'] = $size;
+		// Add frames and link target using g2_filter code from MichelleC
+		$params['albumFrame'] = $album_frame;
+		$params['itemFrame'] = $item_frame;
+		$params['linkTarget'] = $link_target;
+
+		$block = array ();
+		list ($ret, $imageBlockHtml) = GalleryEmbed :: getImageBlock($params);
+		if ($ret) {
+			gallery_error(t('Unable to get Gallery image block'), $ret);
+			return;
+		} else {
+			//if ($imageBlockHtml) {  this line is redundant isn't it?
+			// Add a div around the table for styling
+
+			if ($div_class != 'none') {
+				$imageBlockHtml = '<div class ="giImageBlock '.$div_class.'">'.$imageBlockHtml.'</div>';
+			}
+			// This puts the image block HTML back into the rest of the text
+			$text = str_replace($match[0], $imageBlockHtml, $text);
+			//}
+		}
+	} // end of for loop through matches
+	// If we had at least one match, finish up
+	if (count($matches) > 0) {
+		GalleryEmbed :: done();
+		// Add the CSS link(s)
+		$css_links = '';
+		// In order to use the album/image frames, we need to link to the style sheet(s)
+		$frame_list = array_unique($frame_list);
+		$relative_G2_Path = variable_get('gallery_dir', 'gallery2/');
+		foreach ($frame_list as $frame) {
+			$css_links .= '<link rel="stylesheet" href="'.$relative_G2_Path.'main.php?g2_controller=imageblock.ExternalCSS&amp;g2_frames='.$frame.'"/> ';
+		}
+		// Link to the CSS that controls the styling of the wrapping div
+		$div_css = drupal_get_path('module', 'g2_filter')."/g2_filter.css";
+		$css_links .= '<link rel="stylesheet" href="'.$div_css.'"/> ';
+		$text = $css_links .= $text;
+	}
+	return $text;
+}
+?>
\ No newline at end of file
