Page 1 of 1

Include gallary and forum possible?

Posted: Tue Mar 08, 2005 11:50 am
by chorizo
Hi, Im new to Serendipity and I love it!

But I have to questions that I searched the documentation but haven't found the answer for.

1. Is it possible to include the http://www.minigal.dk into the blog. So that the main part, the part with the text, is replaced with the image gallery?

2. Quite like the first. Is it possible to include a forum inside the blog?

Re: Include gallary and forum possible?

Posted: Tue Mar 08, 2005 1:43 pm
by garvinhicking
Great to hear you enjoy Serendipity!

1. Yes, this is possible using a simple plugin. I do not use nor know minigal, but a Serendipity plugin like this should do:

Code: Select all

<?php

switch ($serendipity['lang']) {
    default:
        @define('PLUGIN_EXTERNALPHP_TITLE', 'External PHP Application');
        @define('PLUGIN_EXTERNALPHP_TITLE_BLAHBLAH', 'Shows an external PHP application inside your blog with your blogs design and all formattings. USE WITH CARE, THIS PLUGIN HAS SECURITY IMPLICATIONS AS IT INCLUDES ANY GENERIC PHP FILE! YOU CAN ONLY USE THIS PLUGIN AS ADMIN!');
        @define('PLUGIN_EXTERNALPHP_PERMALINK', 'Permalink');
        @define('PLUGIN_EXTERNALPHP_PAGETITLE', 'URL shorthand name (Backwards compatibility)');
        @define('PLUGIN_EXTERNALPHP_PERMALINK_BLAHBLAH', 'Defines permalink for the URL. Needs the absolute HTTP path and needs to end with .htm or .html!');
        @define('PLUGIN_EXTERNALPHP_INCLUDE', 'File to include');
        @define('PLUGIN_EXTERNALPHP_INCLUDE_DESC', 'Full absolute path to the PHP file to include');
        @define('PLUGIN_EXTERNALPHP_ARTICLEFORMAT', 'Format as article?');
        @define('PLUGIN_EXTERNALPHP_ARTICLEFORMAT_BLAHBLAH', 'if yes the output is automatically formatted as an article (colors, borders, etc.) (default: yes)');
        break;
}

class serendipity_event_externalphp extends serendipity_event {
    var $title = PLUGIN_EXTERNALPHP_TITLE;
    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name', PLUGIN_EXTERNALPHP_TITLE);
        $propbag->add('description', '');
        $propbag->add('event_hooks',  array('entries_header' => true, 'entry_display' => true, 'genpage' => true));
        $propbag->add('configuration', array('permalink', 'pagetitle', 'include', 'articleformat'));
        $propbag->add('author', 'Garvin Hicking');
        $propbag->add('version', '1.0');
        $propbag->add('requirements',  array(
            'serendipity' => '0.7',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('stackable', true);
    }

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

        switch($name) {
            case 'permalink':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_EXTERNALPHP_PERMALINK);
                $propbag->add('description', PLUGIN_EXTERNALPHP_PERMALINK_BLAHBLAH);
                $propbag->add('default',     $serendipity['rewrite'] != 'none' 
                                             ? $serendipity['serendipityHTTPPath'] . 'pages/phpname.html'
                                             : $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/pages/phpname.html');
                break;

            case 'include':
                // THIS IS AN EVIL EVIL PLUGIN.
                if ($serendipity['serendipityUserlevel'] < USERLEVEL_ADMIN) {
                    return false;
                }

                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_EXTERNALPHP_INCLUDE);
                $propbag->add('description', PLUGIN_EXTERNALPHP_INCLUDE_DESC);
                $propbag->add('default',     $serendipity['serendipityPath'] . 'include/your_php.inc.php');
                break;

            case 'pagetitle':
                $propbag->add('type',        'string');
                $propbag->add('name',        PLUGIN_EXTERNALPHP_PAGETITLE);
                $propbag->add('description', '');
                $propbag->add('default',     'phpname');
                break;

            case 'articleformat':
                $propbag->add('type',        'boolean');
                $propbag->add('name',        PLUGIN_EXTERNALPHP_ARTICLEFORMAT);
                $propbag->add('description', PLUGIN_EXTERNALPHP_ARTICLEFORMAT_BLAHBLAH);
                $propbag->add('default',     'true');
                break;

            default:
                return false;
        }
        return true;
    }

    function show() {
        global $serendipity;

        if ($this->selected()) {
            if (!headers_sent()) {
                header('HTTP/1.0 200');
            }

            if ($this->get_config('articleformat') == TRUE) {
                echo '<div class="serendipity_Entry_Date">
                         <h3 class="serendipity_date">' . PLUGIN_EXTERNALPHP_TITLE . '</h3>';
            }
    
            echo '<h4 class="serendipity_title"><a href="#">' . $this->get_config('headline') . '</a></h4>';
            
            if ($this->get_config('articleformat') == TRUE) {
                echo '<div class="serendipity_entry"><div class="serendipity_entry_body">';
            }
    
            $include_file = realpath($this->get_config('include'));
            ob_start();
            include $include_file;
            $content = ob_get_contents();
            ob_end_clean();
            
            if ($this->get_config('markup') == TRUE) {
                $entry = array('body' => $content);
                serendipity_plugin_api::hook_event('frontend_display', $entry);
                echo $entry['body'];
            } else {
                echo $content;
            }
    
            if ($this->get_config('articleformat') == TRUE) {
                echo '</div></div></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 = PLUGIN_EXTERNALPHP_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;
        }
    }
}
/* vim: set sts=4 ts=4 expandtab : */
I have also just committed this plugin to our additional_plugins CVS repository. To use it, just save the code inside serendipity/plugins/serendipity_event_externalphp/serendipity_event_externalphp.php

You can then install it in your Serendipity Plugin Configuration inside the Event plugin area.

You need to be logged in as admin user to specify the include path, though! You can then set the pagetitle to, like 'minigal' and call your blog via http://blog/pages/minigal.html or also via http://blog/index.php?serendipity[subpage]=minigal

Another way would be to "reverse include" the stuff. That means to edit your minigal scripts and include the Serendipity framework around it. This is called 'embedded mode' and you can find more information about this on www.s9y.org. But you should prefer the plugin way.

You also need to take care how follow-up links of your included PHP application are handled. If they link to subpages, like the forum does, this will be troublesome. For that, search this forum about the topic "gallery". I wrote up much information about how to use Gallery with such a wrapper mode.

Regards,
Garvin

Posted: Tue Mar 08, 2005 7:03 pm
by Guest
Hi, thanks for the quick answer!

But the first solotion didn't work since MiniGal couldent find some files it needs. So I tried the second on and it works, but I get an error:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /customers/stenehall.se/stenehall.se/httpd.www/bilder_mg2/skins/stenehall/templates/thumbnails_begin.php:1) in /customers/stenehall.se/stenehall.se/httpd.www/serendipity/include/functions_config.inc.php on line 474
the line that produces the error is:

Code: Select all

header('X-Serendipity-InterfaceLang: ' . $lang);
Can this be removed without any problem? Or do you have a better solution?

Posted: Tue Mar 08, 2005 7:19 pm
by chorizo
Forgot to login, sorry.

One more thing. Everything apears to work if I remove the line. Im using english as language I quese that is important.

Posted: Wed Mar 09, 2005 11:00 am
by garvinhicking
Thanks for reporting this! Indeed this header is not needed, I added a special check to CVS now so that you won't have to fix it again anywhen :-)

Regards,
Garvin