Gallery2 Website Option Sidebar Block

My website is Lightbox enabled for image viewing and slideshow viewing of Gallery2 contents. Although the default case is to enable these Lightbox services, many website viewers may not want this. Website visitors should have the option to configure their viewing experience to suit their preference. This introduces the idea of user specific customization or configuration of their profile on my website.

To enable customization I implemented a user options section as a new Gallery2 sidebar block. The first challenge was to create a new Gallery2 block. Fortunately there is a very simple HTML page custom plugin for Gallery2 available on the Internet, from Bharat Mediratta, that can be used to do this. I didn’t care about the intended capability to link to HTML pages but I did want the ability to establish a sidebar block. I wanted to display checkbox options in the sidebar that the user could modify. This sidebar block would be shown on all Gallery2 pages so I also needed some way to retain the settings of these checkboxes as the user traversed the gallery pages.

To do this, I had to maintain the user option state in session cookies. The cookies provide persistance to the option values across individual page changes within one session and also across different sessions. I had two Lightbox options custom configured in my Matrix theme that could be used for initial settings. One was a global Lightbox option that identified if Lightbox services were available, and the second identified if Lightbox slideshow capabilities were available. If these options were set in the theme and if cookie values did not exist then I could assume that the checkbox options should be set, otherwise the checkbox option value would be the cookie value. For persistance the cookies would be retained within the browser for five days.

The Gallery2 sidebar block contents, found in the HtmlBlock.tpl template file in the plugin blocks directory, were replaced with the following Javascript:

templates/blocks/HtmlBlock.tpl

{*
 * $Revision: 1.5 $
 * If you want to customize this file, do not edit it directly since future upgrades
 * may overwrite it.  Instead, copy it into a new directory called "local" and edit that
 * version.  Gallery will look for that file first and use it if it exists.
 *}
{if ($theme.params.lightbox == 1)} 
    <script type="text/javascript">
      // <![CDATA[
      function set(s) {ldelim}
        var x = readCookie(s) ;
        if (!x) return ;
        eraseCookie(s) ;
        (x.charAt(0)=='1') ? x = "0" : x = "1" ;
        createCookie(s,x,5) ;
      {rdelim}

	function createCookie(name,value,days) {ldelim}
	  if (days) {ldelim}
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	  {rdelim}
	  else var expires = "";
	  document.cookie = name+"="+value+expires+"; path=/";
	{rdelim}

	function readCookie(name) {ldelim}
	  var nameEQ = name + "=";
	  var ca = document.cookie.split(';');
	  for(var i=0;i < ca.length;i++) {ldelim}
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	  {rdelim}
        if (name == "cb1") return {if ($theme.params.lightbox == 1)} "1" ; {else} "0" ; {/if}
        if (name == "cb2") return {if ($theme.params.autoLightbox == 1)} "1" ; {else} "0" ; {/if}
	  return null;
	{rdelim}

	function eraseCookie(name) {ldelim}
	  createCookie(name,"",-1);
	{rdelim}


    document.write('<div class="{$class}">') ;
    if (readCookie('cb1') == "1")
      document.write('<input type="checkbox" id="cb1" checked="checked" onClick="set('+"'cb1'"+');"/><b>Photo Lightbox on</b><br />') ;
    else 
      document.write('<input type="checkbox" id="cb1" onClick="set('+"'cb1'"+');"/><b>Photo Lightbox on</b><br />') ;
  {if ($theme.params.autoLightbox == 1)} 
    if (readCookie('cb2') == "1")
      document.write('<input type="checkbox" id="cb2" checked="checked" onClick="set('+"'cb2'"+');"/><b>Gallery Slideshow on</b>') ;
    else 
      document.write('<input type="checkbox" id="cb2" onClick="set('+"'cb2'"+');"/><b>Gallery Slideshow on</b>') ;
  {/if}
    document.write('</div>') ;
      // ]]>
    </script>
{/if} 

Meta Tags for Gallery2 and WordPress

When Gallery2 is embedded in WordPress there is no standard capability to generate page meta descriptions and keyword tags for individual Gallery2 albums or photos.  The WPG2 plugin creates one WordPress page, the WPG2 page, in which all Gallery2 content is rendered.  Each time a Gallery2 page is rendered by WordPress we need to be able to generate unique meta tags so that search engines can index and identify our site Gallery2 pages. Without the capability to uniquely tag individual Gallery2 pages our photo galleries may not be indexed.

To generate meta tags for each WordPress Gallery2 page, the first step is to generate meta tags in the Gallery2 header.  In many cases the meta description tag is based upon the Gallery2 page description or title and the meta keyword tag is based upon the Gallery2 page keywords.  In my case I follow similar technique for the page description, but for keywords I want to automatically generate these values from the album contents if keywords were not specified.

Some postings on the Internet show how to do this. Meta tags are inserted into your Gallery2 theme.tpl file near the beginning, after the generation of the <title> directive. I have modified the code to default the keyword values from the Gallery2 summary text and album title. I do not assign Gallery2 keywords to album and photo pages. Instead, my pages use the summary text as a keyword to identify the album contents.

theme.tpl

    
    {* If Gallery doesn't provide a header, we use the album/photo title (or filename) *}
    {if empty($head.title)}
      <title>{$theme.item.title|markup:strip|default:$theme.item.pathComponent}</title>
    {/if}

    {* For meta tags, if no keywords for the page we default to use the title and summary text from all children in the page*}
    {assign var="keywordlist" value=$theme.item.title|markup:strip|default:$theme.item.pathComponent}
    {if count($theme.children) > 0}
       {foreach from=$theme.children item=child}
          {if !empty($child.summary)}
            {if !empty($child.title)}
 	       {assign var="keywordlist" value=$keywordlist|cat:", "}
 	       {assign var="keywordlist" value=$keywordlist|cat:$child.title|markup:strip|entitytruncate:1000}
            {/if}
            {assign var="keywordlist" value=$keywordlist|cat:", "}
	    {assign var="keywordlist" value=$keywordlist|cat:$child.summary|markup:strip|entitytruncate:1000}
         {/if}
       {/foreach}
    {/if}

    <meta name="description" content="{$theme.item.description|markup:strip|truncate:180:'...'|default:$theme.parent.title|markup:strip|default:$theme.item.pathComponent}" />
    <meta name="keywords" content="{$theme.item.keywords|markup:strip|default:$keywordlist}" />


The next step, once the <meta> tags are being generated in the Gallery2 HTML <head> section, is to write a new function in the WPG2 plugin to extract these tags from the Gallery2 page and insert them into the WordPress header. We will use this function in the WordPress header template when we want to write the Gallery2 meta tags. Note, this code isolates only the meta tags which have the ‘name=’ directive. This selects only the meta tags identified above and does not bring forward any other Gallery2 meta tags of different types that may duplicate existing WordPress tags. Edit the wpg2functions.inc file and add the following code:

wpg2functions.inc

/**
* Function Hook on WordPress Header
* WP action to add the Gallery2 meta tags to the WP header
*
* @param NULL
* @return NULL
*/
function g2_addmeta() {

	if (!defined('G2INIT')) {
		$ret = g2_login();
		if ($ret) {
			echo '<h2>' . __('Fatal G2 error', 'wpg2') . '</h2> ' . __("Here's the error from G2: ", 'wpg2') . $ret->getAsHtml();
			exit;
		}
	}

	global $g2data;

	if (defined('WPG2PAGE')) {
		// Merge Gallery2 HEAD Outputs Into WP Header 
		if (isset($g2data['headHtml'])) {
			list($g2_title, $g2_css, $g2_javascript, $g2_meta) = GalleryEmbed::parseHead($g2data['headHtml']);
			foreach ($g2_meta as $wpg2_meta) { 
				if (strpos("$wpg2_meta","name=")) { echo "$wpg2_meta rn"; }
			}
		}
	}
		
	// Add BTEV Event Message
	if (function_exists('btev_trigger_error')) {
		btev_trigger_error('WPG2 ADDED G2 HEADER TO WP HEADER', E_USER_NOTICE, __FILE__);
	}
}


Lastly, you need to find the section in your WordPress header template where meta tags are written. In my case I am using the Atahualpa theme and this theme has put some hooks into the header generation to call special functions. I updated bfa_meta_tags.php and inserted the call to our new function g2_addmeta() in the section where meta tags were generated for static and single post pages. Note, for this solution to work correctly you do not want to define meta tags or descriptions within your WordPress theme for the WPG2 page, otherwise you will generate both the theme meta tags and the Gallery2 meta tags.

functions/bfa_meta_tags.php


// META DESCRIPTION & KEYWORDS Tag for single post pages and static pages:
if ( is_single() OR is_page() ) {
	$bfa_meta_description = get_post_meta($post->ID, 'bfa_ata_meta_description', true);
	$bfa_meta_keywords = get_post_meta($post->ID, 'bfa_ata_meta_keywords', true);
	if ( $bfa_meta_description != '' ) {
		echo "<meta name="description" content="" .
    	htmlentities($bfa_meta_description,ENT_QUOTES,'UTF-8') . "" />n";
	}
	if ( $bfa_meta_keywords != '' ) {
		echo "<meta name="keywords" content="" .
    	htmlentities($bfa_meta_keywords,ENT_QUOTES,'UTF-8') . "" />n";
	}  
	// META DESCRIPTION Tag for WPG2 pages:
	g2_addmeta() ;
}

Rei Ayanami with Entry Plug Interior

As my website is evolving to be more of a blog, I thought I should post some pictures of the model that I am working on now.   I wanted to try something different and this kit caught my fancy.

This model is a resin kit and it is not a PVC figure.  It’s a really weird machine with a figure in it.  The name talks about ‘Entry Plug Interior’?  I have no idea what this means but I suspect it has something to do with the Evangelion machines.  After some research I discovered that this  is the cockpit of the Entry Plug before it enters Rei’s EVA unit.

I want to experiment with some Alclad II lacquers on this – the prismatic type – to see what happens. I am going to try a spectrum of colors on the machine from the front to the back. Gold to green, green to blue, and blue to ultraviolet. It could turn out to be a bust, but so be it …

I’ve used these Alclad prismatic paints before, on a few occasions, and they are sort of interesting. Depending on how you look at the model the paint reflects a different color. And with a high gloss coat I’m hoping this will turn out to be a bit unique?

Rei Ayanami is quite small. It’s going to be quite the feat to paint her eyes! I don’t even know what scale I would put her at.

I’m at the point where I am fitting and priming, and I am almost ready to start painting. The pictures below dhoe what is known as a ‘dry fit’ of the model.  The pieces are assembled but not finished or glued.  Dry fits help to identify any issues with the model before we spend all our time finishing it.

I have to admit, the casting and quality of this model is very good. There are next to no seams of any substance, no pinholes, and everything fit properly to get this thing together. There is a sequence to the assembly that needs to be followed that is not trivial. The pieces almost snap together. About the only flaws were a few thin spots in the casting and the cockpit had to be shaved down a bit to get it to fit into the body of the machine.





As mentioned earlier, the construction sequence for this machine is tricky.  The middle section is composed of two halves that essentially snap together, but while this is done the circular engine disk needs to be positioned in the tail section before everything is glued.  It is important to ensure that all the pieces are fitting correctly before we begin the painting process.  I am likely to use some chrome and other sensitive colors on these pieces and they are going to have to be handled during construction.  If we are not well prepared for the final assembly there could be some damage due to finger prints and glue mistakes.

The first photo shows how the machine is assembled.  The second shows how the seat is positioned in the unit.  The third shows the tail piece assembled with the engine disk inserted.  The last photo shows how the final half of the unit will snap on.  You can see that there will be a seam down the center of the back of the unit.  I’m not sure if I will leave this as a panel line type of seam or if I will have to go back and fill and repaint this after assembly.  We’ll see how it turns out?




Alclad II paints, particularly the chrome, are designed to be put over a gloss black base.  It seems to me that many of their metallic lacquers somehow require the black base behind the paint to provide a reflection for the light.  Alclad claims that other color backings can be used on some of their paints but black is recommended for the particular prismatic paints and others that I intend to use.

As all Alclad paints are lacquer type it seems appropriate to use lacquer paints throughout the painting.  Lacquer paints all dry by evaporation of their solvent.  No chemical reaction occurs in the paint.  They are generally quick to dry and the paint film can be polished.  So, my base black is an Alclad lacquer paint, too.

The first photo below shows most of the parts with their base black color applied.  One thing I discovered is that if the base is applied too thinly it seems to dry in a pebble way rather than as a shiny gloss coat.  I try to sand the pebbles down before the next coat, but sometime this is difficult.  I am almost thinking with this base coat that it needs to be fairly wet so that the gloss coating will dry smoothly.  One problem is that if you don’t clean this up, the final metallic coats will not be smooth.

The second and third photos show what the Alclad prismatic paints look like. The blue to ultraviolet desn’t seem to be particulary distinct or noticable, in that it mostly just appears to be blue. However, the gold to green does reflect quite differently depending on how the light hits the object.




Now that most of the painting is done, it’s time to start the assembly. The back end of the machine has to be assembled as one unit and it will take a minute or so to put all these pieces together. So, I’m using 5 minute epoxy glue. This should give me enough time to glue and assemble and work with the peices before the glue sets.

The first two pictures shows a dry fit before I use glue. You can see the seam that exists down the center of the pieces when the two halves are assembled. I’ll repair this later. Also, I’ve washed a little black paint into the 000 unit numbers on the back of the piece to bring the cast detail out a little. The funny yellow pattern on the side is a decal that I happened to have laying about, so I thought to use it here.

The third picture shows the assembled piece. Note, the chrome part on top has been painted with Alclad chrome and this is a fragile paint. It shouldn’t be touched during assembly I had to hold the pieces with tissue or paper towel.




After assembly I filled the center seam in the back, sanded, sprayed some black base coat and repainted the area. The first picture shows the before and after results. I don’t know about you, but I find that hiding seams like this never works right the first time. Fill, sand, paint, see the missed spots or sanding flaws, fill, sand, paint, again and again. This took about three go-arounds before I was satisfied.

The remaining pictures show the completion of the machine assembly. I have taken pictures with flash and without so you can see the difference. The flash picture throws a shadow. The remaining assembly was fairly straight forward. There were some small screws supplied with the kit that I used to attach the pieces together.

>




The last thing to do is to paint and assemble Rei. Her face and hair fit together as three pieces, but this leaves a seam across her head that needs filling and repainting. The first picture shows her face and the filling I have done to repair the seam. I’ve very slightly oversprayed her face with a pearlescent white to give a little depth and luster to her skin. I’ve yet to put a little white dot in her eyes – I don’t know if I can do this. The face is quite small. The ruler shows centimeters on the left and inches on the right, for scale.

Rei’s body is completely base coated in gloss white for her plug suit. It’s difficult to paint the black trim on her suit. I tried to do this free hand and messed up with the stripes on her legs and had to start again. The second time I masked and sprayed. I am not sure that this was much easier as the masking was tedious and I had to touch up the masking flaws when finished.

Rei’s face and figure generally turned out satisfactorily after the seam on her hair was filled. Final pictures follow.