Static Page Plugin to hold iFrame?

Creating and modifying plugins.
Post Reply
User avatar
RobA
Regular
Posts: 317
Joined: Wed Apr 27, 2005 5:11 pm
Contact:

Static Page Plugin to hold iFrame?

Post by RobA » Tue May 03, 2005 4:02 pm

I wanted to just wrap an extsting page on my server in an iFrame to be displayed in the Article area of the page.

When I do this, the right sidebar disappears.

The code I tried was simply:

Code: Select all

<iframe width="100%" height="100%" frameborder="0" src="/stats/index.html" name="StatFrame" />


Wiewing the page in IE shoes no content at all, and in Firefox the content appears, but no right sidebar (and the width of the iFrame is the remainder of the page).

Any sugestions on a better way to make a page external to the blog appear "embedded" in the blog framework?

Thanks,
-Rob A>

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Static Page Plugin to hold iFrame?

Post by garvinhicking » Tue May 03, 2005 7:04 pm

I'd create a sidebar plugin which includes the file in question instead of using ugly iframes :)

Look at serendipity_plugin_gallery_menalto_random (or sth. like that), this embeds a foreign gallery page into your blog. You could adapt this and embed your own script there...

As for the reason why it failed, I could only tell that if you give me the URL to the blog with that iframe code in it...

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/

User avatar
RobA
Regular
Posts: 317
Joined: Wed Apr 27, 2005 5:11 pm
Contact:

Post by RobA » Tue May 03, 2005 9:48 pm

I've changes it slightly but still the same behaviour.


The "static page" is http://ffaat.pointclark.net/blog/pages/ServerStats.html and the iframe is pointing to
http://ffaat.pointclark.net/stats/system/hour.html

Appreciate you taking a look :)

In the meantime I'll take a look a the sidebar plugin you suggested modifying.

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Wed May 04, 2005 12:40 am

Rob: Using Firefox, it works properly. The IE fails, though. You might need to look up iframe specifications and see why the IE is freaking. I bet it's got something to do with XHTML/Doctype compliance or missing attributes...

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/

User avatar
RobA
Regular
Posts: 317
Joined: Wed Apr 27, 2005 5:11 pm
Contact:

Post by RobA » Wed May 04, 2005 8:49 pm

So I took the code from the static page event plugin, and acked it to be an external page wrapper.

The width problem had to do with CSS stuff, but the solution I found was to put the iframe in a table.

Here is a sample "wrapped" page http://ffaat.pointclark.net/blog/wpages/load.html

that points to http://ffaat.pointclark.net/stats/system/load.html

Here is the ugly beast.

Code: Select all

<?php # $Id: serendipity_event_wrapURL.php, v0.1 2005/05/04

# (c) by Rob Antonishen
# Very much copied from the static page event plugin by Marco Rinck, Garvin Hicking, David Rolston
#


switch ($serendipity['lang']) {

    case 'en':
    default:
        @define('WRAPURL_TITLE', 'WrapURL');
        @define('WRAPURL_TITLE_BLAHBLAH', 'Wraps another page in an IFRAME to be displayed in the body');
        @define('WRAPURL_HEADLINE', 'Headline');
        @define('WRAPURL_HEADLINE_BLAHBLAH', 'Shows a headline above the url which is rendered as every other headline in your blog');
        @define('WRAPURL_URL', 'The URL');
        @define('WRAPURL_URL_BLAHBLAH', 'The URL - either a full URL or relative to the server docroot');
        @define('WRAPURL_HIGHT', 'Height in Pixels');
        @define('WRAPURL_HIGHT_BLAHBLAH', 'This is required because of CSS and table attributes.');
        @define('WRAPURL_PERMALINK', 'Permalink');
        @define('WRAPURL_PAGETITLE', 'URL shorthand name (Backwards compatibility)');
        @define('WRAPURL_PERMALINK_BLAHBLAH', 'Defines permalink for the URL. Needs the absolute HTTP path and needs to end with .htm or .html!');
        break;
}

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

        $propbag->add('name', WRAPURL_TITLE . ': ' . $this->get_config('pagetitle', ''));
        $propbag->add('description', WRAPURL_TITLE_BLAHBLAH);
        $propbag->add('event_hooks',  array('entries_header' => true, 'entry_display' => true, 'genpage' => true));
        $propbag->add('configuration', array('headline', 'permalink', 'pagetitle', 'wrapurl', 'height'));
        $propbag->add('author', 'Rob Antonishen');
        $propbag->add('version', '0.1');
        $propbag->add('requirements',  array(
            'serendipity' => '0.7',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $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',        WRAPURL_HEADLINE);
                $propbag->add('description', WRAPURL_HEADLINE_BLAHBLAH);
                $propbag->add('default',     '');
                break;

            case 'wrapurl':
                $propbag->add('type',        'string');
                $propbag->add('name',        WRAPURL_URL);
                $propbag->add('description', WRAPURL_URL_BLAHBLAH);
                $propbag->add('default',     '');
                break;

            case 'permalink':
                $propbag->add('type',        'string');
                $propbag->add('name',        WRAPURL_PERMALINK);
                $propbag->add('description', WRAPURL_PERMALINK_BLAHBLAH);
                $propbag->add('default',     $serendipity['rewrite'] != 'none'
                                             ? $serendipity['serendipityHTTPPath'] . 'wpages/pagetitle.html'
                                             : $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/wpages/pagetitle.html');
                break;
               
            case 'pagetitle':
                $propbag->add('type',        'string');
                $propbag->add('name',        WRAPURL_PAGETITLE);
                $propbag->add('description', '');
                $propbag->add('default',     'pagetitle');
                break;

            case 'height':
                $propbag->add('type',        'string');
                $propbag->add('name',        WRAPURL_HIGHT);
                $propbag->add('description', WRAPURL_HIGHT_BLAHBLAH);
                $propbag->add('default',     '1000');
                break;


            default:
                return false;
        }
        return true;
    }

    function show() {
        global $serendipity;

        if ($this->selected()) {
            if (!headers_sent()) {
                header('HTTP/1.0 200');
            }
 
            echo '<h4 class="serendipity_title"><a href="#">' . $this->get_config('headline') . '</a></h4>';
           
            echo '<table width="100%" border="0" cellpadding="0" cellspacing="0"><td height=' . $this->get_config('height') . '>';
            echo '<IFRAME src="' . $this->get_config('wrapurl') . '" width="100%" height="100%" scrolling="auto" frameborder="0" style="height:100%;frameborder:0px" ></IFRAME>';
            echo '</td></table>';           


        }
    }

    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 = WRAPURL_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;
        }
    }
}


The only problem with this has to do with the height attribute not existing in tables and height = 100% cascading up to parrent elements all the way to the body and html elements, and CSS stuff that is way over my head. I don't even know php, just doing cut and paste. There were also some javascript solutions I saw on the web but these were considered "bad".

So the configuration interface provides a field to manually enter the height of the iframe, and you have to tweak it to fit the content.

Hope no-one is insulted by this :) It meets my needs, so I'm using it.

-Rob A>

User avatar
RobA
Regular
Posts: 317
Joined: Wed Apr 27, 2005 5:11 pm
Contact:

Post by RobA » Fri May 27, 2005 6:01 pm

I've make this avable as a zip file on my site http://ffaat.pointclark.net/blog/ Use the link in the Stick posting, or the link in the Article menu on the right side.

Is there a better way to make this easier to use for people? As as tar? with directories/permissions set to what?

Is there a "user contributed repository" anywhere where these things can be made available/described?

-Rob A>

User avatar
Wizard
Regular
Posts: 103
Joined: Sat Aug 13, 2005 7:18 am
Location: Southern California
Contact:

wrapURL rocks

Post by Wizard » Sat Aug 13, 2005 7:23 pm

This plugin worked great! I used it to "embed" not only coppermine, but another program I have that catalogs movies. It can output HTML pages with links, photos and other information that I now wrap Serendipity around it. Thanks Rob for the useful program. Here is the link if you want to see it in action. http://www.socalwizard.com/serendipity/index.php?/wpages/mydvds.html
Wizard
My WeBlog

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: wrapURL rocks

Post by garvinhicking » Sun Aug 14, 2005 2:18 am

I just took the liberty to add the plugin to our repository. Thanks a lot, Rob - and I hope this is fine with you? :)

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/

verbatim
Regular
Posts: 43
Joined: Sat Mar 12, 2005 10:53 pm

quick question

Post by verbatim » Fri Sep 16, 2005 10:59 am

quick question

is it posible for the links on the page i embed to be shown inside frames also when they are clicked on?

Just curious to how this would be done?

thanks

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: quick question

Post by garvinhicking » Fri Sep 16, 2005 1:27 pm

Verbatim,

if you add an iframe to a page, all links inside that iframe will be shown within the iframe. Only if the links have a "target=top" or "target=parent" attribute they will break out of the iframe, which cannot be prevented.

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/

verbatim
Regular
Posts: 43
Joined: Sat Mar 12, 2005 10:53 pm

Post by verbatim » Fri Sep 16, 2005 7:42 pm

thanks Garv,

the test page i used happened to be one that would break out of the iframe.

thanks again

Post Reply