[dev] Block applets

Joe Wilson joe.wilson at mindcandy.org
Tue Jul 29 20:53:21 PDT 2003


Here is the patch I promised last week that generalizes the Block portal
interface to allow the addition of new 'applets' without modifying the core
Horde code (e.g. lib/api.php).  Simply add a new entry to
$this->applets[{name}] in registry.php and place the code in
lib/Block/{name}.php.

I have attached an initial set of applets that do the following:

Time - display the time as of the last page update
MOTD - run the 'fortune' program in a portal block
iFrame - display an external web page in an iframe within a block

Other additions welcome.

Best,

Joe

*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
 *#
  *#   Joe Wilson             (917) 690-0507 (c)
   *#   884 Palmer Ave.        (914) 777-3250 (h)
    *#   Mamaroneck, NY 10543
     *#
      *#    He to whom [the mysterious] is a stranger,
       *#    who can no longer pause to wonder and stand
        *#    rapt in awe, is as good as dead: his eyes are closed.
         *#                           - Albert Einstein
          *#
           *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*



-------------- next part --------------
Index: api.php
===================================================================
RCS file: /usr/local/cvs/horde/horde/lib/api.php,v
retrieving revision 1.12
diff -u -r1.12 api.php
--- api.php	29 Jul 2003 20:36:27 -0000	1.12
+++ api.php	30 Jul 2003 03:23:33 -0000
@@ -5,7 +5,7 @@
  * This file defines Horde's external API interface. Other
  * applications can interact with Horde through this API.
  *
- * $Horde: horde/lib/api.php,v 1.11 2003/06/14 04:28:19 chuck Exp $
+ * $Horde: horde/lib/api.php,v 1.10 2003/02/27 00:37:32 jan Exp $
  */
 
 $_services['admin_list'] = array(true);
@@ -51,22 +51,16 @@
 
 function _horde_blocks()
 {
-    $blocks = array();
-    $blocks['color'] = array('name' => _("Color"),
-                             'params' => array('color' => array('name' => _("Color"),
-                                                                'type' => 'color',
-                                                                'default' => '#ff0000'
-                                                                )));
-
-    if ($GLOBALS['conf']['fortune']['enabled']) {
-        $blocks['fortune'] = array('name' => _("Fortune"),
-                                   'params' => array('fortune' => array('name' => _("Fortune"),
-                                                                        'type' => 'fortune',
-                                                                        'default' => $GLOBALS['conf']['fortune']['path']
-                                                                        )));
-    }
+    require_once HORDE_BASE . '/lib/Registry.php';
+    $registry = &Registry::singleton();
 
+    $blocks = array();
+    foreach ($registry->applets as $app => $params) {
+	$blocks[$app] = array('name' => $params['name'],
+	    'params' => array($app => $params));
+	}
     return $blocks;
+
 }
 
 function _horde_admin_list()
-------------- next part --------------
<?php
/**
 * $Horde: horde/lib/Block/iframe.php,v 1.2 2003/01/29 09:47:05 mikec Exp $
 *
 * @package horde
 */
class Horde_iframe_Block extends Horde_Block {

    /* Constructor */
    function horde_iframe_Block($params = array())
    {
        $this->_params = $params;
        $this->_app = 'horde';
        $this->_type = 'iframe';
    }

    /**
     * Does this block have any user editable parameters?
     *
     * @return boolean  True is there are editable paramters
     *                  False if there are not
     */
    function isEditable()
    {
        return true;
    }

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        return _("URL");
    }

    /**
     * The content to go in this block.
     *
     * @return string   The content
     */
    function _content()
    {
//        $html  = '<iframe src="%s" width="90%%" height="90%%" marginheight="5" scrolling="yes" frameborder="1">';
        $html  = '<iframe src="%s" width="90%%" marginheight="5" scrolling="yes" frameborder="1">';
        $html .= '</iframe>';

        return sprintf($html, $this->_params['iframe']);
    }
}
-------------- next part --------------
<?php
/**
 * $Horde: horde/lib/Block/motd.php,v 1.2 2003/01/29 09:47:05 mikec Exp $
 *
 * @package horde
 */
class Horde_motd_Block extends Horde_Block {

    /* Constructor */
    function horde_motd_Block($params = array())
    {
        $this->_params = $params;
        $this->_app = 'horde';
        $this->_type = 'motd';
    }

    /**
     * Does this block have any user editable parameters?
     *
     * @return boolean  True is there are editable paramters
     *                  False if there are not
     */
    function isEditable()
    {
        return false;
    }

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        return _("Message of the Day");
    }

    /**
     * The content to go in this block.
     *
     * @return string   The content
     */
    function _content()
    {
	$html = "<center><b>" . str_replace("\n", "<br>",`/usr/games/fortune`);
        return $html;
    }
}
-------------- next part --------------
Index: registry.php.dist
===================================================================
RCS file: /usr/local/cvs/horde/horde/config/registry.php.dist,v
retrieving revision 1.166
diff -u -r1.166 registry.php.dist
--- registry.php.dist	24 Jul 2003 18:51:38 -0000	1.166
+++ registry.php.dist	30 Jul 2003 03:36:28 -0000
@@ -535,3 +535,29 @@
     'status' => 'active',
     'menu_parent' => 'webserver'
 );
+
+/*
+ * This section defines any
+ * Block portal extensions (applets)
+ */
+$this->applets['color'] = array(
+            'name' => 'Color',
+	    'type' => 'color',
+	    'default' => '#ff0000'
+	);
+
+$this->applets['iframe'] = array(
+            'name' => 'URL',
+	    'type' => 'iframe',
+	    'default' => 'http://www.horde.org'
+	);
+
+$this->applets['motd'] = array(
+            'name' => 'MOTD',
+	    'type' => 'motd'
+    );
+
+$this->applets['time'] = array(
+            'name' => 'Time',
+	    'type' => 'time'
+	);
-------------- next part --------------
<?php
/**
 * $Horde: horde/lib/Block/color.php,v 1.2 2003/01/29 09:47:05 mikec Exp $
 *
 * @package horde
 */
class Horde_time_Block extends Horde_Block {

    /* Constructor */
    function horde_time_Block($params = array())
    {
        $this->_params = $params;
        $this->_app = 'horde';
        $this->_type = 'time';
    }

    /**
     * Does this block have any user editable parameters?
     *
     * @return boolean  True is there are editable paramters
     *                  False if there are not
     */
    function isEditable()
    {
        return false;
    }

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {
        return _("Current Time");
    }

    /**
     * The content to go in this block.
     *
     * @return string   The content
     */
    function _content()
    {
	$html = '<font size="+2">'.strftime("%A, %B %d, %Y %H:%M", time()).'</font>';
        return sprintf($html, $this->_params['time']);
    }
}


More information about the dev mailing list