Integrating gallery sidebar into design

bauke

Joined: 2006-08-20
Posts: 2
Posted: Sun, 2006-08-20 07:42

Hi,
I'm integrating Gallery 2 into OSCommmerce an all is going pretty well. But now I want to unhook the navigation sidebar from Gallery and place it somewhere else in my design.

I thought that something like this would do the trick, but it doesn't:
<?php echo $data['sidebarHtml']; ?>

I know Gallery starts the sidebar by calling this smarty code:
{g->theme include="sidebar.tpl"}
My knowledge of smarty is very limited and i can't seem to get it converted into normal php.

Who can help? I just need to know i can integrate the sidebar into my master php page.

Thnx, Bauke Boorsma

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2006-08-20 13:01
function G2_sideBar()
{

	$needDone = false;
	if ( $g2_data == '' )
	{	
		$ret = G2B_G2_init(); // call your gallery initialization function here. - imporatant!
		
		if ( $ret )
		{
			echo( 'Failed to init() G2.' );
			echo( '   Here is the error message from G2:' );
			echo( $ret->getAsText() );
			
			return;
		}
        GalleryCapabilities::set( 'showSidebarBlocks', false );		
		$g2_data = GalleryEmbed::handleRequest();
		
		$needDone = true;
	}

	if ( !isset( $g2_data['sidebarBlocksHtml'] ) )
	{
		$content = 'You need to enable sidebar blocks in your Gallery 2 theme configuration.';
	}
	else
	{		
		$numSidebars = count( $g2_data['sidebarBlocksHtml'] );
		$sidebarHTML = array();
		
		// first remove blanks entries
		for ( $i = 0; $i < $numSidebars; $i++ )
		{
			$html = trim( $g2_data['sidebarBlocksHtml'][$i] );
			
			if ( $html == '' )
				continue;
			
			$sidebarHTML[] = $html;
		}

		$numSidebars = count( $sidebarHTML );

		$content = '<div id="gsSidebar">';
	
		// now display the ones left over
		for ( $i = 0; $i < $numSidebars; $i++ )
		{
			$content .= $sidebarHTML[$i];
			
			if ( $i != $numSidebars - 1  )
				$content .= '<hr size=1 width="90%" />';
		}
		
		$content .= '</div>';
	}

	if ( $needDone )
		GalleryEmbed::done();

	return $content;
}

try that.

-s

 
bauke

Joined: 2006-08-20
Posts: 2
Posted: Sun, 2006-08-20 13:57

Thanks for your reply, code looks like what i need, but i can't get it working.
I'm still no expert in php, so it's probably a very simple thing that i'm missing here.

I tried to call your script this way:
$content = G2_sideBar();

But that leaves me an empty screen, nothing gets processed from that point on.

In my script i use $data = runGallery(); to initialise my gallery (rungallery() function posted below)

further down my page i call echo $data['bodyHtml'];
to display the gallery on that location.

Now i see you using the variable $g2_data, shouldn't that be $data?

Is this correct for my script?
$ret = G2B_G2_init();
or should i call a different function, because i can't find G2B_G2_init() anywhere.

I'm using:
Gallery versie = 2.1.1 core 1.1.0.1
PHP versie = 4.3.11 apache2handler
Web server = Apache/2.0.53 (Fedora)
Database = mysql 4.1.19, lock.system=flock
Toolkits = Gd
Versnelling = none, none
Besturingssysteem = Linux server9.hosting2go.nl 2.6.12-1.1381_FC3smp #1 SMP Fri Oct 21 04:03:26 EDT 2005 i686
Standaard thema = matrix
Talen = nl_NL
Browser = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; InfoPath.2)

function runGallery() {
    require_once('scrapalbum/embed.php');


    // if anonymous user, set g2 activeUser to ''
    $uid = '';
    
    // initiate G2
    $ret = GalleryEmbed::init(array('g2Uri' => '/scrapalbum/','embedUri' => 'scrapgalerie.php','activeUserId' => $uid));
    if ($ret) {
      $data['bodyHtml'] = $ret->getAsHtml();
      return $data;
    }

    // user interface: you could disable sidebar in G2 and get it as separate HTML to put it into a block
    GalleryCapabilities::set('showSidebarBlocks', false);


    // handle the G2 request
    $g2moddata = GalleryEmbed::handleRequest();


    // show error message if isDone is not defined
    if (!isset($g2moddata['isDone'])) {
      $data['bodyHtml'] = 'isDone is not defined, something very bad must have happened.';
      return $data;
    }
    // exit if it was an immediate view / request (G2 already outputted some data)
    if ($g2moddata['isDone']) {
	exit;
    }

    // put the body html from G2 into the xaraya template
    $data['bodyHtml'] = isset($g2moddata['bodyHtml']) ? $g2moddata['bodyHtml'] : '';

    // get the page title, javascript and css links from the <head> html from G2
    $title = ''; $javascript = array();	$css = array();

    if (isset($g2moddata['headHtml'])) {
      list($data['title'], $css, $javascript) = GalleryEmbed::parseHead($g2moddata['headHtml']);
	  $data['headHtml'] = $g2moddata['headHtml'];
    }


    /* Add G2 javascript  */
    $data['javascript'] = '';
    if (!empty($javascript)) {
      foreach ($javascript as $script) {
	     $data['javascript'] .= "\n".$script;
      }
    }

    /* Add G2 css  */
    $data['css'] = '';
    if (!empty($css)) {
      foreach ($css as $style) {
	     $data['css'] .= "\n".$style;
      }
    }

    // sidebar block
    if (isset($g2moddata['sidebarBlocksHtml']) && !empty($g2moddata['sidebarBlocksHtml'])) {
      $data['sidebarHtml'] = $g2moddata['sidebarBlocksHtml'];
    }

    return $data;
}

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2006-08-20 18:58

Here, try this one:

-s

 
gbdg

Joined: 2005-10-21
Posts: 21
Posted: Sat, 2006-11-11 17:58

Wow suprsidr, this is just what I needed - THANK YOU! It worked perfectly.

http://www.southcoasttu.org/gallery2/g2.php

 
smirking

Joined: 2006-05-10
Posts: 14
Posted: Thu, 2007-11-08 17:17

COOL! Suprsidr, you just saved me a hell of a lot of work! Thanks! Thanks! Thanks!

 
kakajoe

Joined: 2008-02-15
Posts: 5
Posted: Mon, 2008-03-10 20:31

sorry....stupid question ....
what is galleryembed.php for ??
i have a website and i want to place the recent image in index... i use image block ... but its only showing 1 picture.. how can i showing 5 recent picture??

thanks

 
smirking

Joined: 2006-05-10
Posts: 14
Posted: Tue, 2008-03-11 08:50

In the admin area there's a setting you can change to alter the number of images that will be shown in the image block.