[dev] imp: new block with full inbox display

Karsten Fourmont fourmont at gmx.de
Wed Apr 14 08:38:21 PDT 2004


Hi,

I'd like my Horde Portal Page to include a block/applet with a list of messages
in my inbox. (Or the 10 most recent ones)
The provided "summary" block is somewhat too brief for me.

So I extended imp/lib/api's _imp_blocks() like this:

function _imp_blocks()
{
    return array('summary' => array('name' => _("Folder Summary")),
    			 'folder'  => array('name' => _("Folder")) );
}

and added a file imp/lib/Block/folder.php.

The content of the block should basically look like the output of message.php,
so I want to use this as a starting point.
However I ran into a problem.

Currently my folder.php looks like this:

-----folder.php----------------------------
<?php

// very ugly hack to get mailbox content:
global $conf, $notification, $prefs, $registry, $imp, $browser;
global $html_out, $do_filter;
ob_start();
include IMP_BASE . '/mailbox.php';
$html_out= ob_get_contents();
ob_end_clean();
// strip unwanted leading and trailing stuff like <html>....
$html_out=preg_replace(
	'/^.*<html.*?^<table border="0" width="100%">/msi'
	,'<table border="0"><table border="0" class="control">'
	,$html_out);
$html_out=preg_replace('/<\/body.*?$/si','',$html_out);
//end of ugly hack

function get_folder_summary() {

  global $html_out;
  return $html_out;
}

class Horde_Block_Imp_folder extends Horde_Block {

    var $_app = 'imp';

    function _title() { return "Webmail"; }

    function _content()
    {
        global $conf, $notification, $prefs, $registry;

        $authentication = 'none';
        require dirname(__FILE__) . '/../base.php';

        $html = '<table border="0" width="100%">';

        $auth = false;
        if (IMP::checkAuthentication(OP_HALFOPEN, true) === true) {
            $auth = true;

			$html = get_folder_summary();
        } else {
            $html .= '<tr><td class="text">not logged in</td></tr>';
        }

        return $html.'</table>';
    }

}
?>
-----

I don't want to actually include mailbox.php but rather copy the functionality
therein. This is just for demonstration.

The problem is: this only works if the "hack" code resides in the global scope
of folder.php.
If I place it into get_folder_summary where it belongs, I always get an "mo msgs
in this folder" display.
This happens as well if I copy the relevant lines from mailbox.php into
get_folder_summary. I spent some time trying to figure out what's going on but
without any success.

Any ideas? Thanks.

If I manage to get this working (quite a few things have to be changed from the
normal folder display): is there an interest to put this into cvs?

If so we should get the design right. IMHO there are two ways of doing this
1) copy the functionality of mailbox.php to a new lib function which then will
be enhanced to generate normal display as well as the brief block display
2) keep message.php unchanged and create a new function for the block display.

Currently I tend to go for solution 2) but I'm not sure. Depends somewhat on
wether I can reuse the templates.

 Karsten





More information about the dev mailing list