Difference between revisions of "Dynamic Blocks"
(→Dynamic Block API) |
|||
(7 intermediate revisions by 3 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. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | === 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. | |
− | < | + | <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 | ||
− | |||
− | + | 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 | ||
− | < | + | <div align="center"> |
− | The | + | <table cellpadding="2" width="100%" border="1" |
− | + | style="border-collapse: collapse" bordercolor="#111111" | |
+ | cellspacing="0"> | ||
+ | <tr> | ||
+ | <th vAlign="top" width="4%"> </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_<plugin name></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 | + | <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" | + | <td class="codeheader" valign="top" width="5%" align="center"><font |
size="2">1</font></td> | size="2">1</font></td> | ||
− | <td class="codeheader" | + | <td class="codeheader" valign="top" width="10%"><font |
− | size="2"> | + | size="2">plugin_getBlocksConfig_<plugin name></font></td> |
− | <td class="code" | + | <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 | ||
− | |||
− | |||
− | |||
− | |||
</tr> | </tr> | ||
− | |||
</table> | </table> | ||
</div> | </div> | ||
− | + | === 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 | |
− | developer of the Dynamic Block API for a plugin | ||
− | + | 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 | ||
− | . It should return an | ||
− | |||
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 | ||
* $items[] = array('label1' => 'value', 'label2' => 'value') | * $items[] = array('label1' => 'value', 'label2' => 'value') | ||
− | * Basic | + | * 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 $items; | return $items; | ||
} | } | ||
+ | </pre> | ||
+ | </div> | ||
− | |||
− | + | === 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 $ret; | return $ret; | ||
} | } | ||
+ | </pre> | ||
+ | </div> | ||
+ | |||
+ | |||
+ | [[Geeklog Documentation|Main Table of Contents]]<br/> | ||
+ | [[Complete Table of Contents]] | ||
− | + | ||
+ | [[Category:Development]] [[Category:Plugin Development]] [[Category:Blocks]] |
Latest revision as of 22:45, 18 March 2012
Contents
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; }