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
Posts: 8339
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
Posts: 2
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; }Posts: 8339
Here, try this one:
-s
Posts: 21
Wow suprsidr, this is just what I needed - THANK YOU! It worked perfectly.
http://www.southcoasttu.org/gallery2/g2.php
Posts: 14
COOL! Suprsidr, you just saved me a hell of a lot of work! Thanks! Thanks! Thanks!
Posts: 5
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
Posts: 14
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.