[SOLVED] Random Block when Embedded

plop1
plop1's picture

Joined: 2004-04-28
Posts: 16
Posted: Fri, 2005-05-27 10:05

I've noticed that using the url descriptors for embedding into an external page (in my case phpnuke) do not work.

Following the external image block notes on the Image Block Admin within Random/Popular Block of Site Admin states that the following url should be used:

<?php @readfile('http://www.mydomain.com/modules.php?name=gallery2&g2_view=imageblock:External&g2_blocks=randomImage&g2_show=title'); ?>

However using this within a html page inside Nuke displays the entire site module within a site, as opposed to just the photo.

This was never an issue using random block in gallery 1.x.

Using the non embedded link; work's effectively but the link to the photo displayed obviously shows gallery in non-embedded form when clicked.

<?php @readfile('http://www.mydomain.com.com/modules/gallery2/main.php?g2_view=imageblock:External&g2_blocks=randomImage&g2_show=title'); ?>

Any ideas how we can fix this?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-05-27 10:23

plop1, interesting what you try there.

modules.php?name=gallery2 calls your wrapper file. your wrapper file gets the html from G2 and puts it into the phpnuke site.
what you want: if it's an external imageblock request, your wrapper should just return the html that is returned from g2, and not put it into the phpnuke page.

your options:
a) change your wrapper file. after GalleryEmbed::handleRequest(), check if GalleryUtilities::getRequestVariable('g2_view') or just 'view' don't remember, is equal to imageblock:External (or imageblock.External as mindless just changed : to .).
if so, then return the g2 html instead of putting into the phpnuke page (i.e. echo bodyHtml; exit; would do the job).

b) instead of readfile(url), you could use GalleryEmbed::init(); GalleryEmbed::getImageBlock();
GalleryEmbed::done();

c) extend the imageblock:external controler to accept an url parameter, then call main.php with the correct parameters.

 
plop1
plop1's picture

Joined: 2004-04-28
Posts: 16
Posted: Fri, 2005-05-27 11:30

Great,

so If I opt for option b; it should look like this (although it doesn't work as yet) where:

where the following embedded code: is at url http://www.mydomain.com/modules.php?name=genealogy (wrapper to /modules/genealogy/index.html)
gallery2 is at /modules/gallery2

require_once("http://www.mydomain.com/modules/gallery2/embed.php");
$ret = GalleryEmbed::init(array('embedUri' => 'http://www.mydomain.com/modules.php?name=gallery2', 'embedPath' => '/', 'relativeG2Path' => '../gallery2', 'loginRedirect' => '', 'activeUserId' => null));
list ($ret, $imageBlockHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage', 'show' => 'title'));
GalleryEmbed::done();

Any ideas on what I'm doing wrong?

 
michiel_1981

Joined: 2005-05-19
Posts: 430
Posted: Fri, 2005-05-27 12:43

i think activeUserId may not be "null", do you get any errors?

 
plop1
plop1's picture

Joined: 2004-04-28
Posts: 16
Posted: Fri, 2005-05-27 13:38

Solved it!

replace @readfile statement with:
<?
require_once("modules/gallery2/embed.php");
$ret = GalleryEmbed::init(array('embedUri' => 'http://www.mydomain.com/modules.php?name=gallery2', 'embedPath' => '/', 'relativeG2Path' => 'modules/gallery2', 'loginRedirect' => '', 'activeUserId' => null));
list ($ret, $imageBlockHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage', 'show' => 'title'));
echo "$imageBlockHtml";
GalleryEmbed::done();
?>

 
mtakacs
mtakacs's picture

Joined: 2004-04-14
Posts: 4
Posted: Fri, 2005-05-27 13:39

I didnt want to do a full Embedded plugin deal, all I wanted was the randomImage block on my main page. g2 has a nice little one-liner using readfile() that I could have used... EXCEPT .. Im running my site allow_url_fopen = false, which effectly disables that readfile() approach.

In order to get my site to work, I had to replace that one-liner with the block of code below.

my /gallery2/ installation is called /photos/ and this code snippet lives in the page that servers as my main index.php page.

<?php
require_once(dirname(__FILE__) . '/photos/embed.php');
GalleryEmbed::init(array('embedPath' => '/photos/',
                         'fullInit' => false
                         ));
list($ret,$content) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage',
                                                        'show' => 'none'));
GalleryEmbed::done();
echo $content;
?>

And yes, I read the docs at

http://gallery.menalto.com/modules/GalleryAPI/apidoc/GalleryCore/Classes/GalleryEmbed.html#methodinit

but, the formatting for the parameter list is hideous. :)

I needed to use 'fullInit' => false in order for it to work at all as a replacement for the "drop in randomImage", even tho the docs make it sound like an optional param. I also dropped some parameters that were NOT marked as optional and it still works, so Im not entirely sure what to believe anymore :)

-tak

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-05-27 17:55

mtakacs,
oops: just checked the code: we only check for isset($params['fullInit']) and not for $params['fullInit'] == true.
committed the fix to the cvs. get the next nightly to get this change.

so, translating your fullInit = false to the new, corrected code is equal to fullInit = true.
And yes, fullInit is required for the imageblock. right.

plop1, michiel is right, don't set 'activeUserId' => null, set it to 'activeUserId' => '' (empty string).

 
michiel_1981

Joined: 2005-05-19
Posts: 430
Posted: Fri, 2005-05-27 18:31

Strange i tried 'activeUserId' => '' (for quest users)

i got this error:
Input Array does not match ?: SELECT DISTINCT gallery_AccessMap.g_accessListId FROM gallery_AccessMap WHERE (gallery_AccessMap.g_userId = NULL OR gallery_AccessMap.g_groupId IN (1)) AND gallery_AccessMap.g_permission & 1 =

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-05-27 18:54

michiel_1981, this slightly reminds of someone having the same error, but in standalone.

what G2 version are you using?
could you clear all your GALLERYSID cookies in your browser and test if you can browse around as a guest/anonymous user in standalone G2.
then try again this embedded code, with activeUserId => ''.

 
michiel_1981

Joined: 2005-05-19
Posts: 430
Posted: Fri, 2005-05-27 19:20

hehe what clearing cookies can do. It worked.
do you still like to know which version? i think cvs between 18-20 may

0.9.18
2.0-beta-3+

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-05-27 19:23

michiel_1981, good :)

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sat, 2005-05-28 11:20

ozgreg pointed out that fullInit is not needed for getimageblock. and he's right.
you can ommit fullInit in the init call or set it to true for getImageBlock.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sat, 2005-05-28 17:09

Sorry, got to revert that statement.
See: http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&p=142795#142795

fullInit true is needed for getImageBlock().

 
plop1
plop1's picture

Joined: 2004-04-28
Posts: 16
Posted: Sun, 2005-05-29 18:52

All was well; however I've just noticed that a first time visitor to the site gets this error:

    Input Array does not match ?: SELECT DISTINCT g2_AccessMap.g_accessListId FROM g2_AccessMap WHERE (g2_AccessMap.g_userId = NULL OR g2_AccessMap.g_groupId IN (1)) AND g2_AccessMap.g_permission & 1 =

from

require_once("modules/gallery2/embed.php");
$ret = GalleryEmbed::init(array('embedUri' => 'modules.php?name=gallery2', 'embedPath' => '/', 'relativeG2Path' => 'modules/gallery2', 'loginRedirect' => '', 'activeUserId' => 'Guest'));
list ($ret, $imageBlockHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage', 'show' => 'title'));
echo "$imageBlockHtml";
GalleryEmbed::done();

Tried, null '' & guest. Any ideas? (if user goes in and out of gallery2 the error goes away)[/]

 
plop1
plop1's picture

Joined: 2004-04-28
Posts: 16
Posted: Sun, 2005-05-29 19:02

doh.. just reread the use of fullinit code now;

require_once("modules/gallery2/embed.php");
$ret = GalleryEmbed::init(array('embedUri' => 'modules.php?name=gallery2', 'fullInit' => 'true', 'embedPath' => '/', 'relativeG2Path' => 'modules/gallery2', 'loginRedirect' => '', 'activeUserId' => ''));
list ($ret, $imageBlockHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage', 'show' => 'title'));
echo "$imageBlockHtml";
GalleryEmbed::done();