xoops_block plugin and D3 module's block(2)

Date 2007-03-29 04:25:25 | Category: XOOPS

in englishin japanese
I've modified D3 module's blocks can return both "array for template" and "string rendered by the template" by specifying $options['disable_renderer'].

Then I've made a smarty plugin named "xugj_block" based on "xoops_block".

eg)
<{xugj_block file="modules/pico/blocks/blocks.php" func="b_pico_list_show" options="pico|0|"}>
It displays the block.

eg2)
<{xugj_block file="modules/pico/blocks/blocks.php" func="b_pico_list_show" options="pico|0|" assign="myblock"}>
It never displays the block.
You can use a new template variable <{$myblock}> instead.
class/smarty/plugins/function.xugj_block.php

<?php

function smarty_function_xugj_block( $params , &$smarty )
{
	$assign_name = @$params['item'] . @$params['assign'] ;

	$block_file = XOOPS_ROOT_PATH . '/' . @$params['file'] ;

	if( file_exists( $block_file ) ) {
		include_once $block_file ;
		if( function_exists( @$params['func'] ) ) {
			$options = empty( $params['opt'] ) ? explode( '|' , @$params['options'] ) : explode( ',' , @$params['opt'] ) ;
			if( empty( $assign_name ) ) {
				$block = call_user_func( $params['func'] , $options ) ;
				if( empty( $block['content'] ) ) {
					var_dump( array_keys( $block ) ) ;
					echo 'missing "item" in <{xugj_block}>' ;
				} else {
					echo $block['content'] ;
				}
				$block['content'] ;
			} else {
				$options['disable_renderer'] = true ;
				$block = call_user_func( $params['func'] , $options ) ;
				$smarty->assign( $assign_name , $block ) ;
			}
		} else {
			echo 'invalid "func" in <{xugj_block}>' ;
			return ;
		}

	} else {
		echo 'invalid "file" in <{xugj_block}>' ;
		return ;
	}
}

?>




You can read more news at PEAK XOOPS.
http://xoops.peak.ne.jp

The URL for this story is:
http://xoops.peak.ne.jp/md/news/index.php?page=article&storyid=416