Gallery2 + Joomla + G2 Component

williamjhines

Joined: 2007-06-15
Posts: 1
Posted: Fri, 2007-06-15 13:27

I have a quick question that I've stayed up all night for the past 3 nights banging my head against the wall over.

I have a perfectly functioning gallery, with the greypop theme installed. I've butchered the gallery so that the user view only displays a list of thumbnails that upon clicking pull up the lightbox effect:

Quote:
http://www.gottadigit.com/gallery/main.php

I have a perfectly functioning joomla site, with the G2 Component installed - and both Joomla and Gallery2 talk back and forth beautifully.

http://www.gottadigit.com/index.php

I even worked the CSS for the lightbox effects to work throughout the site! Even over the FLASH!

That's where it stops being fun.

Essentially, the way this plugin works - is that the actual gallery2 is not displayed unless it is called by clicking the menu item "Gallery". This would be fine if I just wanted a normal gallery on my site. However, that's not going to work for me. I want to have each album attached to a corresponding news article. The wonderful thing is, I've already played with enough code to mirror the joomla component into a module! (That's what you see below in the white box). So that's done.

By default, unless the main menu gallery item is called, the module displays the main index of the gallery. That's because the database calls for if there is no menu item selected - goto the main index.

So, what I have done is create a text box to enter in the album ID. Once the album ID is entered - I would like for this to be ammended to the end of the url so that way it overrides the main menu function. I am pretty new to Gallery 2 and have spent hours on the API - but am still at a loss. Here's where I'm at with the module:

Quote:
<?php
/**
* @package Mod_gallery2_printalbum
* @copyright (C) 4 The Web
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @version $Id: mod_g2bridge_printalbum.php 89 2006-12-07 16:04:40Z michiel_1981 $
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

require_once("components/com_gallery2/init.inc" );

global $my;

$ret = core::init(false,(core::getParam('user', 'mirror') == 1));
if(!$ret){
print _G2_NOT_CONFIGURED;
exit;
}

/* Should we display the side bar? */
GalleryCapabilities::set('showSidebarBlocks', (core::getParam('display', 'sidebar') == 1));

/* Should we display the login */
GalleryCapabilities::set('login', (core::getParam('display', 'login') == 1));

/* handle the G2 request */
$g2moddata = GalleryEmbed::handleRequest($my->username);

/* show error message if isDone is not defined, is this needed? */
if (!isset($g2moddata['isDone'])) {
print 'isDone is not defined, something very bad must have happened.';
exit;
}

/* die if it was a binary data (image) request */
if ($g2moddata['isDone']) {
exit;
}

/* Set Meta Data */
core::parseHead($g2moddata['headHtml']);

/* Save sidebar in global so we can call it in the module */
$GLOBALS['g2sidebar'] = isset($g2moddata['sidebarBlocksHtml']) ? $g2moddata['sidebarBlocksHtml'] : null;

/* Print gallery content */
print core::decoded($g2moddata['bodyHtml']);

?>

The module calls the init.inc file which looks like this:

<?php
/**
* This file loads and setups our framework for communicating with Gallery 2.
*
* @package g2bridge
* @subpackage core
* @version $Revision: 101 $
* @copyright Copyright (C) 2005 - 2007 4 The Web. All rights reserved.
* @license GNU General Public License either version 2 of the License, or (at
* your option) any later version.
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/**
* defines that path to front-end of this component
*/
define('_G2BPATH', dirname(__FILE__));
/**
* defines that path to back-end of this component
*/
define('_G2BPATH_ADMIN', realpath(dirname(__FILE__).'/../../administrator/components/com_gallery2'));

/**
* Load language file
*/
global $mosConfig_lang;
if (file_exists(_G2BPATH_ADMIN.'/language/'.$mosConfig_lang.'.php')){
include(_G2BPATH_ADMIN.'/language/'.$mosConfig_lang.'.php');
} else {
include(_G2BPATH_ADMIN.'/language/english.php');
}

/**
* Require our core class
*/
require_once( _G2BPATH . '/classes/core.class');

/**
* Check and initiated Configuration
*/
$isConfigured = true;

/* include JoomlaLib */
global $mosConfig_absolute_path;
if(file_exists($mosConfig_absolute_path . '/components/com_joomlalib/jlcoreapi.inc')) {
require($mosConfig_absolute_path . '/components/com_joomlalib/jlcoreapi.inc');
} else {
die(_G2_JOOMLALIB_REQUIRED);
}

/* check serverpath and url against hash, this intercepts direct database changes. */
$g2Uri = core::getParam('core','url');
$g2Path = core::getParam('core','path');

/*$hash = core::getParam('core','hash');
//var_dump($g2Uri, $g2Path, $hash, md5($g2Uri.$g2Path));
if(md5($g2Uri.$g2Path) != $hash){
$isConfigured = false;
}
*/

/* check if embed.php exists */
if(!file_exists($g2Path) || is_dir($g2Path) || strpos(strrev($g2Path),'php.debme') !== 0){
$isConfigured = false;
}

/* set isConfigured */
core::isConfigured($isConfigured);

/**
* Set our base url with correct Itemid
* @note This method won't return sef url in back end but is more reliable
*/
global $database, $Itemid, $mosConfig_live_site;
$query = "SELECT id"
. "\n FROM #__menu"
. "\n WHERE link = 'index.php?option=com_gallery2'"
. "\n AND published = '1'"
. "\n ORDER BY `access`, `parent`, `ordering` ASC";
$database->setQuery( $query );
$ItemidList = $database->loadResultArray();
/* build url according to our current Itemid and our ItemidList */
if(!empty($ItemidList) && in_array($Itemid, $ItemidList)){
$baseUrl = 'index.php?option=com_gallery2&amp;Itemid='.$Itemid;
} else if(!empty($ItemidList)){
$baseUrl = 'index.php?option=com_gallery2&amp;Itemid='.(int) $ItemidList[0];
} else {
$baseUrl = 'index.php?option=com_gallery2&amp;Itemid=99999999';
}
/* store base url */
if(function_exists('sefRelToAbs')){
core::setParam('core', 'baseurl', sefRelToAbs($baseUrl),false);
} else {
core::setParam('core', 'baseurl', rtrim($mosConfig_live_site, '/').'/'.$baseUrl,false);
}
/* store embedUri */
$tmp = parse_url(core::getParam('core', 'baseurl'));

$embedUri = isset($tmp['path']) ? $tmp['path'] : '' ;
$embedUri .= isset($tmp['query']) ? '?'.$tmp['query'] : '' ;
core::setParam('core', 'embedUri', $embedUri,false);
?>

So that's it. I'd prefer not to bypass the inc file to go directly to embed.php and write 5 paragraphs of album calling code if I could avoid it. Besides, I don't have the skill...

Any help would be appreciated...I feel like I'm missing an ,$myValue in an array to add the ItemID to the url.........

Thanks again!!!! PS, Amazing work to the developers of this and the g2 bridge!!!

- William