Problems to display images in wordpress without login

bigs

Joined: 2006-10-25
Posts: 20
Posted: Wed, 2006-10-25 14:40

Hello, I use WPG2 plug-in and wpg2id tag to insert photos in my Wordpress blog, I want to put some permissions to my albums to limit access to registered persons. The problem is when you arrive on the blog, photos are not display for guest users and I want to display them on the blog for all persons, and when they click on they arrive on the login window or it do nothing...
Thank you
PS: I prefer continue to use wpg2id tag

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2006-10-25 15:35

hmm, found a funny solution for that.
thanks to mindless' multiroot module, this should be easy.

in gallery 2.2 (current nightly snapshot), there's a module called "multiroot".
"site admin -> plugins -> multiroot -> configure" shows the configuration screen to create multiroots.

you can go there and generate a new multiroot. as option you should specify a name for a new guest user, you can leave the rest empty.
it will generate some code for you and all you need from there is:

$gallery->setConfig('anonymousUserId', 1055);

you should place that in your wpg2 integration right after the GalleryEmbed::init call.

so much for code changes.
now all what you have to do is go to your gallery and remove the view permissions from the everybody group.
and then add the view permissions to the embedGuest user.

all wpg2 guests will act as embedGuest while all standalone gallery guests act as the normal guest in g2.

btw: gallery 2.2 should be 100% compatible with any wpg2 integration that works with gallery 2.1 already.

 
bigs

Joined: 2006-10-25
Posts: 20
Posted: Wed, 2006-10-25 19:07

Thank you very much for your fast answer. I have gallery2 2.2 version. I generate the multiroot, it generates the ID and all seem to be OK; just one thing goes wrong: when I display the modules list, multiroot state is displayed with a red cross...however the user is in the permissions list.

My problem is that I can't find the place where I must insert:

Quote:
$gallery->setConfig('anonymousUserId', 1055);

I just found the "GalleryEmbed::init call" in modules/core/classes/GalleryEmbed.class

Quote:
class GalleryEmbed {

/**
* Return the major and minor version of the Embedding API.
* Make sure to specify the 'apiVersion' parameter in the GalleryEmbed::init call!
*
* @see GalleryCoreApi::getApiVersion, the same rules and notes apply to the Embedding API
* @return array major number, minor number
*/
function getApiVersion() {
return array(1, 2);
}

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2006-10-25 20:08

that the multiroot module shows as red cross is fine. it's module that cannot be activated. after installing it, you can use its configuration view.

and you don't need to edit modules/core/classes/GalleryEmbed.class.
you need to edit wpg2's GalleryEmbed::init call. i don't know the wpg2 code, but somewhere in the wp / g2 bridge files, there must be one or more GalleryEmbed::init calls.

 
bigs

Joined: 2006-10-25
Posts: 20
Posted: Thu, 2006-10-26 07:34

I find the file "wp-content/plugins/wpg2/g2embed.php" but I didn't arrive to find the right place to insert the ligne.

in this script there is 2 functions:
g2_init

Quote:
function g2_init() {
// Get Gallery2 Option Settings
$g2_option = get_settings('g2_options');
// Test if Plugin has been validated.
if (!defined('G2_EMBED') && $g2_option['g2_validated'] == "Yes" )
define('G2_EMBED', 'True');
if (!defined ('G2_EMBED') ) {
echo '<h2>' . __('Fatal Gallery Plug-in error', 'wpg2') . '</h2> ' . __('Plug-in options not validated', 'wpg2');
exit;
}
require_once($g2_option['g2_filepath'].'embed.php');
// Initialise GalleryAPI
$ret = GalleryEmbed::init( array(
'embedUri' => $g2_option['g2_embeduri'],
'g2Uri' => $g2_option['g2_url'],
'loginRedirect' => $g2_option['g2_errorredirect'],
'fullInit' => true )
);
if ($ret) {
$ret->getAsHtml();
return $ret;
}
// Declate G2 Init so we do not do it again..
define("G2INIT", "True");
if ($ret) {
$ret->getAsHtml();
}
return $ret;
}

g2_login

Quote:
function g2_login() {
// Get Gallery2 Option Settings
global $g2_option;
// Get WordPress's CurrentUser
if (isset($_COOKIE['wordpressuser_' . COOKIEHASH]))
$user_login = $_COOKIE['wordpressuser_' . COOKIEHASH];
$userdata = get_userdatabylogin($user_login);
$user_ID = $userdata->ID;
if (!defined('G2INIT')) {
$ret = g2_init();
if (!$ret)
if ($user_ID)
g2_manage_wpg2user($user_ID);
else
GalleryEmbed::checkActiveUser('');
if ($ret) {
$ret->getAsHtml();
}
return $ret;
}
}

I trie to insert the line in different places and nothing work. It think that I must insert the line in the function g2_login but I don't find how and where...
Do you think that it's the right place ?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2006-10-26 11:22

do it in g2_init after the GalleryEmbed::init(...) call.

 
bigs

Joined: 2006-10-25
Posts: 20
Posted: Tue, 2006-10-31 08:14

I try this before and in other places but it doesn't work!!
Maybe I must change other things ?

The line I insert:
$gallery->setConfig('anonymousUserId', 52473);

 
bigs

Joined: 2006-10-25
Posts: 20
Posted: Tue, 2006-10-31 08:23

How can I test the new guest user in gallery2 to be sure that I put the right permissions.

 
bigs

Joined: 2006-10-25
Posts: 20
Posted: Tue, 2006-10-31 16:44

Hello, I make a file test.php and I include the script who is generate by the multiroot plug-in

Quote:
<?php
require('/blog/gallery2/embed.php');
$ret = GalleryEmbed::init(
array('embedUri' => '/gallery2/main.php',
'g2Uri' => '/gallery2/',
'apiVersion' => array(1, 2)
));
if ($ret) {
print '<body>' . $ret->getAsHtml() . '</body>';
return;
}

$gallery->setConfig('login', true);
$gallery->setConfig('defaultAlbumId', 7);
$gallery->setConfig('anonymousUserId', 52473);

GalleryMain();
?>

the file work well and albums permissions are correct.

have you another ideas to include the 'anonymousUserId' in g2embed.php (maybe I must wait for the official gallery2 version 2.2 )

Thank you very much for your help

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2006-11-01 10:41

i don't know the wpg2 integration.
the $gallery->setConfig('anonymousUserId', 52473);
call should be before the initsecondpass.
that means, wpg2's GalleryEmbed::init shouldn't do a fullInit.
And wpg2 shouldn't override the activeUser later in the request somehow.

Maybe a developer of wpg2 could help you based on this information.

 
bigs

Joined: 2006-10-25
Posts: 20
Posted: Wed, 2006-11-01 22:53

Thank you valiant, I try to have more suggetions on the wpg2 forum, if I have the solution I'will post here a new message to give the information. :-)

 
bigs

Joined: 2006-10-25
Posts: 20
Posted: Mon, 2008-04-14 20:20

Hi, I know that it's an old post but I hope that I can resolve it now.
I found something interesting in the file wpg2embed.inc.
Firstely I create a new user in WP and I grant it for gallery2.
I give permissions to this user to view all albums in gallery2
I change the line in wpg2embed.inc to give the WP user ID "36" as parameter

Quote:
// Otherwise Guest
$ret = GalleryEmbed::checkActiveUser('36');

After that, when you arrive on the first page of my site you can see all thumbnails and you are not login in WP. If you enter your login and your password you override the last g2_login and everything run as I want.

Something goes wrong; when you are guest and you click on a thumbnail you can acces to all my albums. My idea is to use the g2_logout function when the page finish to load but I don't know how and where I can do this.

If someone have any suggestions or other proposition !!!

Best regards

 
ozgreg
ozgreg's picture

Joined: 2003-10-18
Posts: 1378
Posted: Thu, 2008-04-17 01:15

Hiya Bigs,

Firstly you will need to change that code back... and after that line of code add what Valiant has pointed out to you in the first posting..

$gallery->setConfig('anonymousUserId', 36);

Hope this helps..

____________________________________
Wordpress / Gallery2 (WPG2) Plugin, , WPG2 Documentation, WPG2 Demo

 
bigs

Joined: 2006-10-25
Posts: 20
Posted: Thu, 2008-04-17 07:35

In my case the ID 36 correspond to a WP User and not to a G2 user. At first I try to creat a user in WP who is link with a guest user generate by the multiroot module but it's not possible because the guest user didn't appear to grant it in WP. Maybe it's possible to link the guest user of wordpress with the alternative guest user generate by the multiroot module.
I had try to insert the code you suggest with an alternative guest user id generate by the multiroot, but nothing worked and the page stop to load at the first thumbnail.