1
synikal
$options on blocks?
  • 2004/12/23 4:28

  • synikal

  • Just popping in

  • Posts: 25

  • Since: 2004/12/11


When I make a block:

function b_loc_welcome($options)

What are the $options or where can I find documentation on the $options?

thanks

2
Dave_L
Re: $options on blocks?
  • 2004/12/23 5:33

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


In xoops_version.php, $modversion['blocks'][*]['options'] is a string containing a list of the default option values, separated by pipes (|).

In the block's show-function and edit-function, the parameter, customarily named $options, is an array whose elements are the current option values.

The show-function's purpose is to display the block's contents.

The edit-function's purpose is to return a string containing the HTML form fragment that's used for editing the block options on the Block Administration page.

Here's an example, from my chess module. There are two options: the maximum number of games displayed in the block, and a code (1,2 or 3) indicating which kind of games to display. The default values are 4 and 3, respectively.

xoops_version.php
...
// Blocks
$modversion['blocks'][1]['file']        = 'blocks.php';
$modversion['blocks'][1]['name']        = _MI_CHESS_GAMES;
$modversion['blocks'][1]['description'] = _MI_CHESS_GAMES_DES;
$modversion['blocks'][1]['show_func']   = 'b_chess_games_show';
// options: maximum number of games to display | 1=show games in play only/2=show concluded games only/3=show both
$modversion['blocks'][1]['options']     = '4|3';
$modversion['blocks'][1]['edit_func']   = 'b_chess_games_edit';
$modversion['blocks'][1]['template']    = 'chess_block_games.html';


blocks/blocks.php
function b_chess_games_show($options)
{
   ...
   
$limit intval($options[0]); // sanitize with intval()

   
switch($options[1]) {
      case 
1:
         
$where "pgn_result = '*'";
         break;
      case 
2:
         
$where "pgn_result != '*'";
         break;
      default:
         
$where 1;
         break;
   }

...

function 
b_chess_games_edit($options)
{
   
$show_inplay    $options[1] == "checked='checked'" '';
   
$show_concluded $options[1] == "checked='checked'" '';
   
$show_both      $options[1] == "checked='checked'" '';

   
$form "
      "
._MB_CHESS_NUM_GAMES.": <input type='text' name='options[0]' value='{$options[0]}' size='3' maxlength='3' />
      <br />
      <input type='radio' name='options[1]' value='1' 
$show_inplay    /> "._MB_CHESS_SHOW_GAMES_INPLAY."
      <input type='radio' name='options[1]' value='2' 
$show_concluded /> "._MB_CHESS_SHOW_GAMES_CONCLUDED."
      <input type='radio' name='options[1]' value='3' 
$show_both      /> "._MB_CHESS_SHOW_GAMES_BOTH."
   "
;

   return 
$form;
}
...


In this case the option values happen to be numbers, but they can be arbitrary strings.

Login

Who's Online

179 user(s) are online (118 user(s) are browsing Support Forums)


Members: 0


Guests: 179


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits