SMF integration and problems with return urls

adamsjd

Joined: 2005-04-02
Posts: 21
Posted: Wed, 2005-05-11 11:19

edit by moderator:
this topic was split from
http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=27024&
</edit>

A am having trouble with this GET variable in the URL of my partially embedded G2 as well.

The URL that it gives me has the g2_return variable that if I remove, causes the page to work fine....

Doesn't work
http://www.outersurf.com/index.php?action=gallery&g2_view=core:ItemAdmin&g2_subView=comment:AddComment&g2_itemId=14&g2_return=http%3A%2F%2Fwww.outersurf.com%2Findex.php%3Faction%3Dgallery%26g2_view%3Dcore%3AShowItem%26g2_itemId%3D43798&g2_returnName=album

Works Great
http://www.outersurf.com/index.php?action=gallery&g2_view=core:ItemAdmin&g2_subView=comment:AddComment&g2_itemId=14&g2_return=&g2_returnName=album

(note that unless you are logged into my main site you won't have permissions to add a comment, and Embedded Gallery doesn't seem to handle it all that well)

Seperate to this I also have an issue with a chdir() error when ever I try to use ImageMagik. I have tried turning on debugging but don't get any furhter information. When I run the test on the ImageMagik module I get the following...

Quote:
chdir() : No such file or directory (errno 2)
File: /home5/www/gallery/modules/core/classes/GalleryPlatform.class
Line: 1005

Gallery version = 2.0-beta-2+ core 0.9.16
PHP version = 4.3.1 apache
Webserver = Apache/1.3.27 (Unix) PHP/4.3.1
Database = mysql 4.0.12
Toolkits = ArchiveUpload, Exif, ImageMagick, Thumbnail
Operating system = FreeBSD outersurf.com 5.0-RELEASE FreeBSD 5.0-RELEASE #0: Sun Apr 6 23:15:43 ADT 2003 :/usr/src/sys/i386/compile/FIREWALL i386
Browser = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0

Quote:
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-05-11 12:12

adamsjd, i fail to see the connection to the prior posts in this topic? can we split your post from this thread to form a new topic?

plus, could you define what "partially embedded" means and what exactly embedded Gallery doesn't handle too well?
thanks.

 
adamsjd

Joined: 2005-04-02
Posts: 21
Posted: Wed, 2005-05-11 12:15

You can, I posted because it was the g2_return= parameter variable in the URL that breaks my embedded application. Feel free to split.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-05-11 13:40

adamsjd, ah sorry. that was obviously also the problem in the topic. you're right, lets discuss your problem here.

could you describe what "doesn't work" means? does the site just not load at all?
and if you perhaps could give as a test account that has the ability to create comments, then we could see the problem for ourselfs.

plus: what about G2 standalone? do the urls with the return parameter work in g2 standalone?

 
adamsjd

Joined: 2005-04-02
Posts: 21
Posted: Wed, 2005-05-11 14:25

valiant, here are the details.

I have started to try to embed G2 into my SMF forums. I have upgraded with the latest CVS and created the functions to init gallery and sync users.

When I run Gallery stand alone ( http://www.outersurf.com/gallery/ ) I have no problem with the g2_return value. When I run it embeded ( http://www.outersurf.com/?action=gallery ) the g2_return value seems to break. Let me give you an example.

Go to http://www.outersurf.com and login with

:asdf33@adf.com

Click on the Users Photo Albums link on the left menu. Then use the drop down menu to try to add a comment.

You will notice that rather than taking you to a page to enter a comment it just displays the gallery album that it was on before the comment.

If you remove the g2_return variable out of the URL it does show you the add comment field.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-05-11 14:48

hmm, can i see your integration code?

i guess the problem could be there.
make sure to have something like this around your handleRequest() call:

 // handle the G2 request
    $g2moddata = GalleryEmbed::handleRequest();
  
    // show error message if isDone is not defined
    if (!isset($g2moddata['isDone'])) {
      $data['g2modhtml'] = 'isDone is not defined, something very bad must have happened.';
      return $data;
    }
    // die if it was a binary data (image) request
    if ($g2moddata['isDone']) {
      exit; /* uploads module does this too */
    }
 
adamsjd

Joined: 2005-04-02
Posts: 21
Posted: Wed, 2005-05-11 15:58
function _gallery_handle_request() {
  static $result;
  global $user_info;

  if (!$result) {
    _gallery_init();

    
    if($user_info['is_admin'])
    {
        GalleryCapabilities::set('showSidebar',true);
    }
    else
    {
    GalleryCapabilities::set('showSidebar',false);
    }
    
    GalleryCapabilities::set('showPathbar', true);
    $result = GalleryEmbed::handleRequest();
   
     return $result;
    
    
  }

function _gallery_init($full = false) {
  global $ID_MEMBER, $user_info;

  require_once('/home5/www/gallery/embed.php');

  $params = array('embedUri' => 'index.php?action=gallery',
                    'embedPath' => "/",
                  'relativeG2Path' => '/gallery',
                  'loginRedirect' => '/index.php?action=login',
                  'activeUserId' => $ID_MEMBER,
                  'activeLanguage' => 'enUS');
                  
  GalleryEmbed::init($params);

  $ret = GalleryEmbed::isExternalIdMapped($ID_MEMBER, 'GalleryUser');
  if ($ret->isError()) {
       if ($ret->isError() && ($ret->getErrorCode() & ERROR_MISSING_OBJECT))
       {
         GalleryEmbed::createUser("$ID_MEMBER", array('username' => $user_info['username'],
                                                 'email' => $user_info['email'],
                                                 'fullname' => $user_info['name'],
                                                 'language' => 'enUS',
                                                 'hashedpassword' => $user_info['passwd'],
                                                 'hashmethod' => 'md5'));               
       }
       
        return false;
  }   
  
}
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-05-11 16:16

adamsjd, ok. but you didn't show what you do after you call _gallery_handle_request().
Could you show that code too? Or just add the snippet from my last post.

a note on your init code:
you'll only have to call GalleryEmbed::isExternalIdMapped(...) if you receive an error status on GalleryEmbed::init.
You save at least one db query / request that way.

 
adamsjd

Joined: 2005-04-02
Posts: 21
Posted: Wed, 2005-05-11 16:24

valiant, I added the bit of code as required for upload and binary transfers....

function _gallery_handle_request() {
  static $result;
  global $user_info;

  if (!$result) {
    _gallery_init();

    GalleryCapabilities::set('showSidebar',false);
    if($user_info['is_admin'])
    {
        GalleryCapabilities::set('showSidebar',true);
    }

    GalleryCapabilities::set('showPathbar', true);
    $result = GalleryEmbed::handleRequest();

     if (!isset($result['isDone'])) {
      $data['g2modhtml'] = 'isDone is not defined, something very bad must have happened.';
      return $data;
    }
    // die if it was a binary data (image) request
    if ($result['isDone']) {
      exit; /* uploads module does this too */
    }

  }

  return $result;
}

The actual code that is used to in the emApp is as follows

function ShowGallery()
{
        global $scripturl, $modSettings, $sourcedir,$context;
        global $txt, $board, $topic, $db_prefix, $user_info, $context, $ID_MEMBER, $language;
        global $galleryOutput;
        loadTemplate('Outersurf');
        $context['sub_template'] = 'gallery';
        $galleryOutput=_gallery_handle_request();


        // insert the title, and any css or java required, note that the theme has to pick this info up too.
        list($title, $css, $javascript) = GalleryEmbed::parseHead($galleryOutput['headHtml']);

        $context['page_title'] = "OuterSurf.com . . . . . . . . . . . . where Halifax Surfs - " . $title;

        foreach($css as $cssEntity)
        {
                $totalCss = $totalCss .  $cssEntity;
        }
        $context['gallery2']['css'] = $totalCss;

        foreach($javascript as $javascriptEntity)
        {
                $totalJava = $totalJava .  $javascriptEntity;
        }
        $context['gallery2']['java'] = $totalJava;
}
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-05-11 16:47

hmm, strange. can't explain why the return redirects don't work.

a few notes:
- why does an embedded G2 request on your site call http://www.outersurf.com/sundaysnap/variables.php ?

- in your function _gallery_handle_request(), make sure to adapt my code snippet a little. this code shouldn't be called anytime, but still, you should do something else than just copy $data into your code. (you don't use it anywhere).

do you use something like output buffering or so?

 
adamsjd

Joined: 2005-04-02
Posts: 21
Posted: Wed, 2005-05-11 17:05

valiant,

- your code has been adopted

- http://www.outersurf.com/sundaysnap/variables.php is where some variables are held for a the flash file on the left hand side, where did you see reference to this file?

- yes my emApp uses output buffering (as far as I know)

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-05-11 17:27

this output buffering could be the reason for your problem.
- either deactivate output buffering for the G2 module
- or what you could try: if isDone == true , then call ob_end_flush or ob_end_clean(); and after that exit;
don't know if that works.

 
adamsjd

Joined: 2005-04-02
Posts: 21
Posted: Wed, 2005-05-11 18:07

valiant I tried the flushing without any luck.

What is the g2_return used for? Is it the url that is returned to after the action (such as adding a comment) is completed?

I'm not sure how buffering would cause Gallery to not understand the required action the URL if there is a g2_return. I can use the exact same URL without the g2_return and it works like a charm.

The following two links demonstrate the problem, no login required.

http://www.outersurf.com/index.php?action=gallery&g2_view=core:ItemAdmin&g2_subView=comment:AddComment&g2_itemId=39542&g2_return=http%3A%2F%2Fwww.outersurf.com%2Findex.php%3Faction%3Dgallery%26g2_view%3Dcore%3AShowItem%26g2_itemId%3D39537&g2_returnName=album

vs.

http://www.outersurf.com/index.php?action=gallery&g2_view=core:ItemAdmin&g2_subView=comment:AddComment&g2_itemId=39542&g2_returnName=album

Update: interstingly this URL works, so it is something at the end of the g2_return URL

http://www.outersurf.com/index.php?action=gallery&g2_view=core:ItemAdmin&g2_subView=comment:AddComment&g2_itemId=39542&g2_return=http%3A%2F%2Fwww.outersurf.com&g2_returnName=album

 
adamsjd

Joined: 2005-04-02
Posts: 21
Posted: Thu, 2005-05-12 11:24

any thoughts on how I can go about trying to debug why the last part of the g2_return url causes G2 to not display the proper module?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2005-05-12 17:02

Either your webserver/php or your G2 embed code is causes query parameters in your urls to be urldecoded twice.. we expect g2_return to be urldecoded so the value is the whole url.. this is not happening.. instead the url is urldecoded once and then processed into the parameters for the request. Example:

http://www.outersurf.com/index.php?action=gallery&g2_view=core:ItemAdmin&g2_subView=comment:AddComment&g2_itemId=43354&g2_returnName=album&g2_return=http%3A%2F%2Fwww.outersurf.com%2Findex.php%3Faction%3Dgallery%26g2_view%3Dcore%3AShowItem%26g2_itemId%3D43321%26g2_page%3D2
We expect these parameters:
g2_view = core:ItemAdmin
g2_subView = comment:AddComment
g2_itemId = 43354
g2_returnName = album
g2_return = http://www.outersurf.com/index.php?action=gallery&g2_view=core:ShowItem&g2_itemId=43321&g2_page=2

Instead we get:
g2_view = core:ShowItem (2nd value overwrites first, I guess)
g2_subView = comment:AddComment (ignored since ShowItem doesn't use subView)
g2_itemId = 43321
g2_page = 2
g2_return = http://www.outersurf.com/index.php?action=gallery (I think)

You'll need to track down why this is happening.

If we compensate for the problem by urlencoding twice, it works:
http://www.outersurf.com/index.php?action=gallery&g2_view=core:ItemAdmin&g2_subView=comment:AddComment&g2_itemId=43354&g2_returnName=album&g2_return=http%253A%252F%252Fwww.outersurf.com%252Findex.php%253Faction%253Dgallery%2526g2_view%253Dcore%253AShowItem%2526g2_itemId%253D43321%2526g2_page%253D2
(not a solution of course, just evidence..)

 
adamsjd

Joined: 2005-04-02
Posts: 21
Posted: Fri, 2005-05-13 01:18

Had to change

	// Are we going to need to parse the ; out?
	elseif ((strpos(@ini_get('arg_separator.input'), ';') === false || @version_compare(PHP_VERSION, '4.2.0') == -1) && !empty($_SERVER['QUERY_STRING']))
	{
		// Get rid of the old one!  You don't know where it's been!
		$_GET = array();

		// Was this redirected?  If so, get the REDIRECT_QUERY_STRING.
		
			$_SERVER['QUERY_STRING'] = urldecode(substr($_SERVER['QUERY_STRING'], 0, 5) == 'url=/' ? $_SERVER['REDIRECT_QUERY_STRING'] : $_SERVER['QUERY_STRING']);

		// If magic_quotes_gpc isn't off, remove the slashes from the get variables.  (they're gonna be html'd anyway.)
		if (get_magic_quotes_gpc() != 0)
			$_SERVER['QUERY_STRING'] = stripslashes($_SERVER['QUERY_STRING']);

		// Replace ';' with '&' and '&something&' with '&something=&'.  (this is done for compatibility...)
		parse_str(preg_replace('/&(\w+)(&|$)/', '&$1=$2', strtr($_SERVER['QUERY_STRING'], ';', '&')), $_GET);
	}

into

	// Are we going to need to parse the ; out?
	elseif ((strpos(@ini_get('arg_separator.input'), ';') === false || @version_compare(PHP_VERSION, '4.2.0') == -1) && !empty($_SERVER['QUERY_STRING']) && ($_GET['action']!='gallery'))
	{
		// Get rid of the old one!  You don't know where it's been!
		$_GET = array();

		// Was this redirected?  If so, get the REDIRECT_QUERY_STRING.
		
			$_SERVER['QUERY_STRING'] = urldecode(substr($_SERVER['QUERY_STRING'], 0, 5) == 'url=/' ? $_SERVER['REDIRECT_QUERY_STRING'] : $_SERVER['QUERY_STRING']);

		// If magic_quotes_gpc isn't off, remove the slashes from the get variables.  (they're gonna be html'd anyway.)
		if (get_magic_quotes_gpc() != 0)
			$_SERVER['QUERY_STRING'] = stripslashes($_SERVER['QUERY_STRING']);

		// Replace ';' with '&' and '&something&' with '&something=&'.  (this is done for compatibility...)
		parse_str(preg_replace('/&(\w+)(&|$)/', '&$1=$2', strtr($_SERVER['QUERY_STRING'], ';', '&')), $_GET);
	}

in the core of the emApp applitcation. seemed to work. Thanks for all the help in tracking down the issue.