Difference between revisions of "Dynamic Blocks"

From GeeklogWiki
Jump to: navigation, search
m (fixed links)
(Dynamic Block API)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Dynamic Block Plugin API in Geeklog 1.4
+
== Dynamic Block Plugin API in Geeklog 1.4 ==
  
 +
The dynamic block plugin API is a new feature of Geeklog 1.4. This new API function allows plugin developers to create left and right blocks in Geeklog on the fly without adding a block to the blocks table. This is accomplished by inserting the block data directly into the array of blocks that is created from a SQL call to the blocks table before it is used to create what is displayed. What follows is an description of the API call and its use in a plugin.
  
<p>The dynamic block plugin API is a new feature of Geeklog 1.4. This new API function alows plugin
 
developers to create left and right blocks in Geeklog on the fly without adding a block to the blocks table.
 
This is acomplished by inserting the block data directly into the aray of blocks that is created from a SQL
 
call to the blocks table before it is used to create what is displayed. What follows is an description of the
 
API call and its use in a plugin..</p>
 
  
 +
=== Dynamic Block API ===
  
<h3>Dynamic Block API</h3>
+
This section will describe and document how to enable your plugin to use the Geeklog dynamic block API. This will be a useful feature of plugin functionality for many developers and it has been designed to be easy to integrate into your plugin. We have done our best to make this straightforward.
  
<p>This section will describe and document how to enable your plugin to use the Geeklog dynamic block API.
+
<b>NOTE:</b> You will need to be using Geeklog version 1.4 or later to successfully use the Dynamic Block API. This plugin API is only available in Geeklog 1.4 and is not present in previous versions of Geeklog.
This will be a usefull feature of plugin functionality for many developers and it has been designed to be easy to integrate
 
into your plugin. We have done our best to make this straight forward </p>
 
  
<p><b>NOTE:</b> You will need to be using Geeklog version 1.4 or later to successfully use the Dynamic Block API. This
+
There is only one plugin function that is required to support dynamic blocks in a plugin. The example function that is included in this explanation are very complete. You should only need to edit them for your plugin name name. The following table summarizes the functions:
plugin API is only avaliable in Geeklog 1.4 and is not present in previous versions of Geeklog.</p>
 
  
<p>There is only one plugin function that is requiered to support dynamic blocks in a plugin.  
+
<div align="center">
The example function that is included in this explanation are very complete.  
+
  <table cellpadding="2" width="100%" border="1"
You should only need to edit them for your plugin name name. The following table summarizes the functions:</p>
+
style="border-collapse: collapse" bordercolor="#111111"
 +
cellspacing="0">
 +
    <tr>
 +
      <th vAlign="top" width="4%">&nbsp;</th>
 +
      <th vAlign="top" width="31%">Function</th>
 +
      <th vAlign="top" width="95%">Description of Function</th>
 +
 
 +
    </tr>
 +
    <tr>
 +
  <td class="codeheader" valign="top" width="5%" align="center"><font
 +
size="2">1</font></td>
 +
  <td class="codeheader" valign="top" width="10%"><font
 +
size="2">plugin_getBlocks_&lt;plugin name&gt;</font></td>
 +
  <td class="code" valign="top" width="85%"><font size="2">This
 +
function expects two parameters:  side and topic. This function is called when a left and right blocks are created with COM_showBlocks in lib-common.php. It is up to the plugin to make sure that the requesting user has sufficient permissions to view any blocks that are returned. It should return an array of block data containing the dynamically generated blocks that you wish the user to see.</font></td>
 +
    </tr>
 +
  </table>
 +
</div>
 +
 
 +
As of Geeklog 2.0.0 there is one additional plugin function that can be used. It is not required to support dynamic blocks in a plugin. The plugin function allows the configuration options to be displayed in the Admin Block Editor to make it easier for Admins to see all blocks that can be displayed on the site. If Admins wish to edit the configuration of these dynamic blocks they do so in the Geeklog Configuration (if the plugin supports this). The following table summarizes the functions:
  
 
<div align="center">
 
<div align="center">
   <table cellPadding="2" width="100%" border="1"
+
   <table cellpadding="2" width="100%" border="1"
 
style="border-collapse: collapse" bordercolor="#111111"
 
style="border-collapse: collapse" bordercolor="#111111"
 
cellspacing="0">
 
cellspacing="0">
Line 33: Line 46:
 
     </tr>
 
     </tr>
 
     <tr>
 
     <tr>
  <td class="codeheader" vAlign="top" width="5%" align="center"><font
+
  <td class="codeheader" valign="top" width="5%" align="center"><font
 
size="2">1</font></td>
 
size="2">1</font></td>
  <td class="codeheader" vAlign="top" width="10%"><font
+
  <td class="codeheader" valign="top" width="10%"><font
size="2">plugin_getBlocks_&lt;plugin name&gt;</font></td>
+
size="2">plugin_getBlocksConfig_&lt;plugin name&gt;</font></td>
  <td class="code" vAlign="top" width="85%"><font size="2">This
+
  <td class="code" valign="top" width="85%"><font size="2">This
function expects two parameters:  side and topic
+
function expects two parameters:  side and topic. This function is called by the Admin Block Editor.</font></td>
. This function is called when a left and right blocks are created with COM_showBlocks in lib-common.php. 
 
It is up to the plugin to make sure that
 
the requesting user has sufficient permissions to veiw any blocks that are returned
 
. It should return an aray of block data containing the dynamicaly generated blocks
 
that you wish the user to see.</font></td>
 
 
     </tr>
 
     </tr>
 
 
   </table>
 
   </table>
 
</div>
 
</div>
  
<h3>Function Details and Examples</h3>
+
=== Function Details and Examples ===
  
<p>Examples provided here have been provided from an initial example created by the  
+
Examples provided here have been provided from an initial example created by the developer of the Dynamic Block API for a plugin currently in development
developer of the Dynamic Block API for a plugin curently in development</p>
 
  
<p>This function expects two parameters:  side and topic
+
This function expects two parameters:  side and topic. This function is called when a left and right blocks are created with COM_showBlocks in lib-common.php. It is up to the plugin to make sure that the requesting user has sufficient permissions to view any blocks that are returned. It should return an array of block data containing the dynamically generated blocks that you wish the user to see.
. This function is called when a left and right blocks are created with COM_showBlocks in lib-common.php.
 
It is up to the plugin to make sure that the requesting user has sufficient permissions to veiw any blocks that are returned
 
. It should return an aray of block data containing the dynamicaly generated blocks
 
that you wish the user to see.<p>
 
  
  
Line 64: Line 66:
 
border-width: 1; background-color: #DDDDDD; padding: 6px 6px 6px 6px;
 
border-width: 1; background-color: #DDDDDD; padding: 6px 6px 6px 6px;
 
font-size: x-small">
 
font-size: x-small">
 +
<pre>
 
/**
 
/**
 
* Returns blocks for this plugin that should appear when COM_showBlocks is run
 
* Returns blocks for this plugin that should appear when COM_showBlocks is run
Line 69: Line 72:
 
* NOTE: this MUST return the label/value pairs in the following format
 
* NOTE: this MUST return the label/value pairs in the following format
 
* &#36;items[] = array('label1' => 'value', 'label2' => 'value')
 
* &#36;items[] = array('label1' => 'value', 'label2' => 'value')
* Basic avaliable lables are..
+
* Basic available labels are..
 
*  name    Name of block (BLOCK_ID)
 
*  name    Name of block (BLOCK_ID)
 
*  type      Must always be set 'dynamic' unless you use advanced API labels
 
*  type      Must always be set 'dynamic' unless you use advanced API labels
Line 141: Line 144:
 
   return &#36;items;
 
   return &#36;items;
 
&#125;
 
&#125;
 +
</pre>
 +
</div>
  
</div>
 
  
<h3>Function PLG_getBlocks() for refrence</h3>
+
=== Function PLG_getBlocks() for reference ===
  
 
<div style="white-space:pre; border: solid; border-color: black;
 
<div style="white-space:pre; border: solid; border-color: black;
 
border-width: 1; background-color: #DDDDDD; padding: 6px 6px 6px 6px;
 
border-width: 1; background-color: #DDDDDD; padding: 6px 6px 6px 6px;
 
font-size: x-small">
 
font-size: x-small">
 
+
<pre>
 
/**
 
/**
 
* gets Geeklog blocks from plugin's
 
* gets Geeklog blocks from plugin's
Line 190: Line 194:
 
     return &#36;ret;
 
     return &#36;ret;
 
&#125;
 
&#125;
 
+
</pre>
 
</div>
 
</div>
  
Line 196: Line 200:
 
[[Geeklog Documentation|Main Table of Contents]]<br/>
 
[[Geeklog Documentation|Main Table of Contents]]<br/>
 
[[Complete Table of Contents]]
 
[[Complete Table of Contents]]
 +
 +
 +
[[Category:Development]] [[Category:Plugin Development]] [[Category:Blocks]]

Latest revision as of 22:45, 18 March 2012

Dynamic Block Plugin API in Geeklog 1.4

The dynamic block plugin API is a new feature of Geeklog 1.4. This new API function allows plugin developers to create left and right blocks in Geeklog on the fly without adding a block to the blocks table. This is accomplished by inserting the block data directly into the array of blocks that is created from a SQL call to the blocks table before it is used to create what is displayed. What follows is an description of the API call and its use in a plugin.


Dynamic Block API

This section will describe and document how to enable your plugin to use the Geeklog dynamic block API. This will be a useful feature of plugin functionality for many developers and it has been designed to be easy to integrate into your plugin. We have done our best to make this straightforward.

NOTE: You will need to be using Geeklog version 1.4 or later to successfully use the Dynamic Block API. This plugin API is only available in Geeklog 1.4 and is not present in previous versions of Geeklog.

There is only one plugin function that is required to support dynamic blocks in a plugin. The example function that is included in this explanation are very complete. You should only need to edit them for your plugin name name. The following table summarizes the functions:

  Function Description of Function
1 plugin_getBlocks_<plugin name> This function expects two parameters: side and topic. This function is called when a left and right blocks are created with COM_showBlocks in lib-common.php. It is up to the plugin to make sure that the requesting user has sufficient permissions to view any blocks that are returned. It should return an array of block data containing the dynamically generated blocks that you wish the user to see.

As of Geeklog 2.0.0 there is one additional plugin function that can be used. It is not required to support dynamic blocks in a plugin. The plugin function allows the configuration options to be displayed in the Admin Block Editor to make it easier for Admins to see all blocks that can be displayed on the site. If Admins wish to edit the configuration of these dynamic blocks they do so in the Geeklog Configuration (if the plugin supports this). The following table summarizes the functions:

  Function Description of Function
1 plugin_getBlocksConfig_<plugin name> This function expects two parameters: side and topic. This function is called by the Admin Block Editor.

Function Details and Examples

Examples provided here have been provided from an initial example created by the developer of the Dynamic Block API for a plugin currently in development

This function expects two parameters: side and topic. This function is called when a left and right blocks are created with COM_showBlocks in lib-common.php. It is up to the plugin to make sure that the requesting user has sufficient permissions to view any blocks that are returned. It should return an array of block data containing the dynamically generated blocks that you wish the user to see.


/**
* Returns blocks for this plugin that should appear when COM_showBlocks is run
*
* NOTE: this MUST return the label/value pairs in the following format
* $items[] = array('label1' => 'value', 'label2' => 'value')
* Basic available labels are..
*   name     Name of block (BLOCK_ID)
*   type       Must always be set 'dynamic' unless you use advanced API labels
*                Advanced API means you set all fields that COM_showBlocks 
*                expects to see from the blocks table. All labels are column names
*   title        Title of block
*   blockorder     Block order number
*   content         Body of the block (the html output)
*   help            Optional url to a help page
*
*  You must only return left or right blocks based on $side and
*  you must also do your own security checks. Everything you send 
*  will show up on a page load
* 
*
* 
*/
function plugin_getBlocks_glcommerce($side, $topic='' )
{
    global $_CONF, $_USER, $HTTP_SERVER_VARS, $REQUEST_URI, $sess, $db;
    // only show on a page in the plugin's dir
    If (in_string('glcommerce', $REQUEST_URI))
   {
        // generate left blocks
        if ($side=='left')
        {

            $display1 = glc_makemenu();
            $display2 = glc_latestprod();

            $items[] = array('name' => 'glcommerce_1',
                                           'type' => 'dynamic',
                                           'onleft' => 1,
                                           'title' => 'Shop Menu', 
                                           'blockorder' => 1,
                                           'content' => $display1, 
                                           'help' => '/glcommerce/help.html');

            $items[] = array('name' => 'glcommerce_2',
                                           'type' => 'dynamic',
                                           'onleft' => 1,
                                           'title' => 'Latest Products ',
                                           'blockorder' => 1,
                                           'content' => $display2,
                                           'help' => '/glcommerce/help.html');

        } else {
        // else generate right blocks
            $display3 = glc_featuredprod()'
            $display4 = glc_minicart();

            $items[] = array('name' => 'glcommerce_3', 
                                           'type' => 'dynamic',
                                           'onleft' => 0,
                                           'title' => 'Featured Stuff',
                                           'blockorder' => 1,
                                           'content' => $display3, 
                                           'help' => '/glcommerce/help.html'); 

            $items[] = array('name' => 'glcommerce_4',
                                           'type' => 'dynamic',
                                           'onleft' => 0,
                                           'title' => 'My Cart', 
                                           'blockorder' => 1, 
                                           'content' => $display4, 
                                           'help' => '/glcommerce/help.html'); 

       }

   }
   return $items;
}


Function PLG_getBlocks() for reference

/**
* gets Geeklog blocks from plugin's
*
* Returns data for blocks on a given side and, potentially, for
* a given topic.
*
* @param        string      $side       Side to get blocks for (right or left for now)
* @param        string      $topic      Only get blocks for this topic
* @return   array of block data
*
*/
function PLG_getBlocks( $side, $topic='')
{
    global $_PLUGINS;

    $ret = array();
    foreach ($_PLUGINS as $pi_name)
    {
        $function = 'plugin_getBlocks_' . $pi_name;
        if (function_exists($function))
        {
            $items = $function($side, $topic='');
            if (is_array ($items))
            {
                $ret = array_merge ($ret, $items);
            }
        }
    }

    // future code to do a lib-custom function
    /*
    if (function_exists('CUSTOM_getBlocks')) {
       $cust_items .= CUSTOM_getBlocks($side, $topic='');
       if (is_array ($cust_items)) {
          $ret = array_merge ($ret, $cust_items)
       }
    }
    */
    return $ret;
}


Main Table of Contents
Complete Table of Contents