Attempting to embed G2

Discussion corner for Developers of Serendipity.
axelseaa
Regular
Posts: 49
Joined: Fri Dec 23, 2005 7:13 pm

Attempting to embed G2

Post by axelseaa »

I am trying to embed a Gallery2 page into serendpity starting with the gallery recommended way to embed g2. Those instructions can be found at http://codex.gallery2.org/index.php/Gal ... edded_mode.

So far I have assemebled the following page called gallery2.php inside my s9y install directory:

Code: Select all

<?php
$g2_Config['path'] = '/path/to/gallery2/';
$g2_Config['embedPath'] = '/s9y/';
$g2_Config['relativeG2Path'] = '../gallery2/';
$g2_Config['embedUri'] = 'gallery2.php';
//print_r($g2_Config);
require_once( $g2_Config['path'] . 'embed.php');
$ret = GalleryEmbed::init(array(
                           'embedPath' => $g2_Config['embedPath'],
                           'relativeG2Path' => $g2_Config['relativeG2Path'],
                           'embedUri' => $g2_Config['embedUri'],
                           'fullInit' => 'false',
                           'gallerySessionId' => $_COOKIE['PHPSESSID']
                           ));
        GalleryCapabilities::set('login',true);

     // handle the G2 request
        $g2moddata = GalleryEmbed::handleRequest();
   // show error message if isDone is not defined
   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; /* uploads module does this too */
   }
    if ($ret->isError())
    {
      print $ret->getAsHtml();
    }

         ?>
         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html>
        <head>
        <?php
        $headHtml = $g2moddata['headHtml'];
        //$headHtml = str_ireplace('</title>', ' -- ' . 'My Site' . '</title>', $headHtml);
        echo $headHtml;
        ?>
        <style type="text/css">  </style>
        </head>
        <body>
embed me!
        <div class="gallery">
        <?php
        echo $g2moddata['bodyHtml'];
        ?>
        </div>
look, i have feet!
        </body>
        </html>

Gallery works just fine from this one page. Now my question is, how do i go about wrapping the style into this page? What is the best way to accomplish this?

Alternatively, is there a plugin where i could just insert this code above as the content? (i remember seeing a static page plugin)

I'm open to idea's. I read through the other gallery emebd threads, and nothing out there works for G2.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Attempting to embed G2

Post by garvinhicking »

Hi!

Sadly I myself am not a Gallery user.

You might want to have a look at the "externalphp" event plugin or the "wrapurl" event plugin. Both provide a way to embed foreign data on a serendipity page, and I guess that you'll have the best success with one of those two plugins...?

G2 is technically very advanced. I am quite sure it would be possible to embed it within serendipity pretty nicely, but there's an initial effort that needs to be coded for that to get it all together. Sadly I cannot dedicate this time to it, but maybe other skilled PHP devs can lend a helping hend? Maybe you want to also ask on the G2 forums about this?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
axelseaa
Regular
Posts: 49
Joined: Fri Dec 23, 2005 7:13 pm

Post by axelseaa »

My goal is to attempt to understand how I could embed this into Serendipity and then figure it out :). I'll ask around the gallery forums as well, but it doesn't seem like anyone has attempted this yet.

Running the embeded gallery, it only ever calls the page that's listed in my first post. All navigation around the gallery site is done by arguments to that page. That's why I think now if I can just get the look and feel of serendipity to surround it, we will be in business.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Did you try the two plugins? Maybe they'll get you further as a kickstart. :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
axelseaa
Regular
Posts: 49
Joined: Fri Dec 23, 2005 7:13 pm

Post by axelseaa »

I plan on trying them later today, i'll report back my findings.
axelseaa
Regular
Posts: 49
Joined: Fri Dec 23, 2005 7:13 pm

Post by axelseaa »

Posted below is the code im working with. Now my next question is, how do you remove the sidebar from the page? When your actually going to view a single image in gallery 2, I want to remove the sidebar so there is more screen to work with. Is this doable?

Code: Select all

<?php 
# (c) by Aaron Axelsen
# Much copied from the wrap url plugin
#

// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
    include $probelang;
}

@define('G2EMBED_TITLE', 'Gallery2 Embed');
@define('G2EMBED_TITLE_DESC', 'Embeds Gallery2 within Serendipity');
@define('G2EMBED_G2DIR', 'Gallery2 Directory');
@define('G2EMBED_G2DIR_DESC', 'Absolute path to the Gallery2 directory on the server.');
@define('G2EMBED_EMBEDPATH', 'Embed Path');
@define('G2EMBED_EMBEDPATH_DESC', 'Absolute path to directory were the embedded file will reside.');
@define('G2EMBED_EMBEDURI', 'Embeded file name');
@define('G2EMBED_EMBEDURI_DESC', 'Name of the file to embed gallery 2 into.');
@define('G2EMBED_PAGETITLE', 'URL shorthand name (Backwards compatibility)');
@define('G2EMBED_PERMALINK', 'Permalink');
@define('G2EMBED_PERMALINK_DESC', 'Defines permalink for the URL.');
@define('G2EMBED_HEADLINE', 'Headline');
@define('G2EMBED_HEADLINE_DESC', 'Defines the heading for the document.');
@define('G2EMBED_RELG2PATH', 'Relative path to Gallery2 directory.');
@define('G2EMBED_RELG2PATH_DESC', 'This should be the relative path to the Gallery2 installation.');

class serendipity_event_G2EMBED extends serendipity_event {
    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name', G2EMBED_TITLE . ': ' . $this->get_config('pagetitle', ''));
        $propbag->add('description', G2EMBED_TITLE_DESC);
        $propbag->add('event_hooks',  array('entries_header' => true, 'entry_display' => true, 'genpage' => true));
        $propbag->add('configuration', array('g2dir', 'embedPath', 'relativeG2Path', 'embedUri', 'headline', 'permalink', 'pagetitle'));
        $propbag->add('author', 'Aaron Axelsen');
        $propbag->add('version', '0.1');
        $propbag->add('requirements',  array(
            'serendipity' => '0.9.1',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('groups', array('FRONTEND_EXTERNAL_SERVICES'));
        $propbag->add('stackable', true);
        
        $this->pagetitle = $this->get_config('pagetitle', 'pagetitle');
    }

    function introspect_config_item($name, &$propbag)
    {
        global $serendipity;

        switch($name) {
		    case 'headline':
				$propbag->add('type',        'string');
                $propbag->add('name',        G2EMBED_HEADLINE);
                $propbag->add('description', G2EMBED_HEADLINE_DESC);
				$propbag->add('default',     'Photo Gallery');
			 	break;
		    case 'g2dir':
				$propbag->add('type',        'string');
                $propbag->add('name',        G2EMBED_G2DIR);
                $propbag->add('description', G2EMBED_G2DIR_DESC);
				$propbag->add('default',     '/var/www/html/gallery2');
			 	break;
		    case 'embedPath':
				$propbag->add('type',        'string');
                $propbag->add('name',        G2EMBED_EMBEDPATH);
                $propbag->add('description', G2EMBED_EMBEDPATH_DESC);
				$propbag->add('default',     $serendipity['serendipityHTTPPath']);
			 	break;
		    case 'relativeG2Path':
				$propbag->add('type',        'string');
                $propbag->add('name',        G2EMBED_RELG2PATH);
                $propbag->add('description', G2EMBED_RELG2PATH_DESC);
				$propbag->add('default',     '../gallery2');
			 	break;
		    case 'embedUri':
				$propbag->add('type',        'string');
                $propbag->add('name',        G2EMBED_EMBEDURI);
                $propbag->add('description', G2EMBED_EMBEDURI_DESC);
				$propbag->add('default',     'gallery2.html');
			 	break;	
            case 'permalink':
                $propbag->add('type',        'string');
                $propbag->add('name',        G2EMBED_PERMALINK);
                $propbag->add('description', G2EMBED_PERMALINK_DESC);
                $propbag->add('default',     $serendipity['rewrite'] != 'none' 
                                             ? $serendipity['serendipityHTTPPath'] . 'gallery2.html'
                                             : $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/gallery2.html');
                break;
                
            case 'pagetitle':
                $propbag->add('type',        'string');
                $propbag->add('name',        G2EMBED_PAGETITLE);
                $propbag->add('description', '');
                $propbag->add('default',     'gallery2');
                break;

            default:
                return false;
        }
        return true;
    }

    function show() {
        global $serendipity;

        if ($this->selected()) {
            if (!headers_sent()) {
                header('HTTP/1.0 200');
            }
            
			require_once( $this->get_config('g2dir') . 'embed.php');
			$ret = GalleryEmbed::init(array(
							   'embedPath' => $this->get_config('embedPath'),
							   'relativeG2Path' => $this->get_config('relativeG2Path'),
							   'embedUri' => $this->get_config('embedUri'),
							   'fullInit' => 'false',
							   'gallerySessionId' => $_COOKIE['PHPSESSID']
							   ));
			GalleryCapabilities::set('login',true);
	
			// handle the G2 request
			$g2moddata = GalleryEmbed::handleRequest();

			// show error message if isDone is not defined
			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; /* uploads module does this too */
			}
			if ($ret->isError())
			{
				print $ret->getAsHtml();
			}

            echo '<h4 class="serendipity_title"><a href="' . $this->get_config('embedUri') . '">' . $this->get_config('headline') . '</a></h4>';
			echo '<div id="gallery">' . $g2moddata['headHtml'] . $g2moddata['bodyHtml'] .'</div>';
        }
    }

    function selected() {
        global $serendipity;

        if ($serendipity['GET']['subpage'] == $this->get_config('pagetitle') ||
            preg_match('@^' . preg_quote($this->get_config('permalink')) . '@i', $serendipity['GET']['subpage'])) {
            return true;
        }
        
        return false;
    }
    
    function generate_content(&$title) {
        $title = G2EMBED_TITLE.' ('.$this->get_config('pagetitle').')';
    }

    function event_hook($event, &$bag, &$eventData, $addData = null) {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');

        if (isset($hooks[$event])) {
            switch($event) {
                case 'genpage':
                    $args = implode('/', serendipity_getUriArguments($eventData, true));
                    if ($serendipity['rewrite'] != 'none') {
                        $nice_url = $serendipity['serendipityHTTPPath'] . $args;
                    } else {
                        $nice_url = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/' . $args;
                    }

                    if (empty($serendipity['GET']['subpage'])) {
                        $serendipity['GET']['subpage'] = $nice_url;
                    }
                    break;                

                case 'entry_display':
                    if ($this->selected()) {
                        if (is_array($eventData)) {
                            $eventData['clean_page'] = true; // This is important to not display an entry list!
                        } else {
                            $eventData = array('clean_page' => true);
                        }
                    }

                    if (version_compare($serendipity['version'], '0.7.1', '<=')) {
                        $this->show();
                    }

                    return true;
                    break;

                case 'entries_header':
                    $this->show();

                    return true;
                    break;

                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
}
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Garvin can probably answer this in a second. I just wanted you to know that I'm looking, and your post hasn't been ignored.

There's some $serendipity field you can modify to prevent plugins from being called. I'll let you know if I can figure out what it is.

You could hook frontend_generate_plugins and set the first parameter to an empty array. I'm still not an expert with PHP, but I think it's passed by reference, and therefore modifiable. That seems a lot better than mucking with $serendipity. Give it a try and tell me what happens.

Anyway. Some themes still reserve space for the plugins, even if there's nothing there. So that'd be a problem, too. Maybe you'd be better off putting G2 in an iframe with a link at the top/bottom to return to the blog?
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Judebert is absolutely right. You can shortcircuit the sidebar listing with a plugin like this: http://nopaste.php-q.net/187840

I added the frontned_generate_plugins circuit. I also committed a patch to 1.0 SVN trunk that allows to also set the Smarty $leftSideBarElements variable if your plugin does not emit plugins. This might go along smoother with Smarty Templates that check if sidebar elements exist.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
axelseaa
Regular
Posts: 49
Joined: Fri Dec 23, 2005 7:13 pm

Post by axelseaa »

I got the sidebar all figured out. Thanks. But now, I was wondering how to load a different template when certain parts of the gallery are loaded. Basically wherever i remove the sidebar, id like to have a template load which utilizes the full screen (ie without the sidebar div).

Is this easily accomplishable? Here is the current code:

http://nopaste.php-q.net/188057
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Yes, you can just set $serendipity['template'] to a different template.

Remember though that this makes your plugin less workable in other environments, because you would also need to ship a custom template with your plugin. Thus, I recommend you to make that template switching optional and a plugin config item, to tell which template to switch to.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
axelseaa
Regular
Posts: 49
Joined: Fri Dec 23, 2005 7:13 pm

Post by axelseaa »

Valid point on the template. I just feel the only way its going to truly look decent is to have the full screen realestate. But, I have been trying to do everything in such a way that its flexible. I'll have to see what I come up with later today, i'm eager to get this working!
axelseaa
Regular
Posts: 49
Joined: Fri Dec 23, 2005 7:13 pm

Post by axelseaa »

When I asked about changing the template, what I was invisioning was just being able to have a different .tpl file, for example gallery.tpl, to display the page. The $serendipity['template'] appears to hold the name of the theme. I took a look at all the smarty variables, but I dont know enought about smarty to understand how that all works just yet.

Is there an easy way to do this?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

You cannot actually just switch the template filename to be parsed. What you can do, though, is to short-circuit all the actions that Serendipity performs to parse a template, and do it within your template.

The cachesimple plugin uses some kind of this routine. What you seem to want to call is the functionality of serendipity_smarty_shutdown() function, with customized parameters, I guess?

The question also is - what do you want to parse? If your plugin takes over, there usually are no entries to parse...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
axelseaa
Regular
Posts: 49
Joined: Fri Dec 23, 2005 7:13 pm

Post by axelseaa »

Here is the part of the index.tpl

Code: Select all

<div id="content" class="narrowcolumn">
    {$CONTENT}
</div>
Basically all i need to do is change the class to say "widecolumn" so the content div can have the full width of the template.

It's probably just easier if I have an option to set the width of the div, granted then that would only work for themes which have a set width, and not a percentage.

Any suggestions on the best path to follow?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Actually I think, your plugin just should do the Smarty parsing on its own. Look at a few example plugins like staticpage, contactform, newsbox or forum. All of them parse stuff within the s9y layout, but with their own smarty templates. You can then put the *.tpl files to use inside your plugin directory...

Messing with the CSS and widths is not a good idea, as it would then need to be different in each template where you embed your plugin. The way above though would have a bit of abstraction for the content-pane, I guess...

But then again, usually people DO want to have the sidebars. If not, it would be easier to just put your blog header look into a G2 template, and you wouldn't need all the embedding trouble. :-)

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply