Page 1 of 1

New Module v2.0 to include BBDKP blocks

Posted: 13. October 2012 00:10
by kiwipearls
I just swtiched over to Board 3 portal thinking that implementing blocks from BBDKP portal would be easy. As BBDKP portal used version 1 block types.

But seeing 2 changed over the need to modify portal.php by creating modules for blocks I am very very stuck.

I asked BBDKP for help, but they don't understand how the new version 2 works.

This is my post I posted at BBDKP:
My results so far using the Board3 v2.0 instructions are that I can get it to call the block kindaof, but I do not know how to include the php in the module. The whole idea in version 2 is that you don't edit portal.php you put your php into modules for the blocks.

/knowledge/kb_show.php?id=54

This is my module - which calls on the block.

Code: Select all

<?php
/**
*
* @package Board3 Portal v2 - Upcoming
* @copyright (c) Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* @package Upcoming
*/
class portal_upcoming_module
{
	/**
	* Allowed columns: Just sum up your options (Exp: left + right = 10)
	* top		1
	* left		2
	* center	4
	* right		8
	* bottom	16
	*/
	public $columns = 8;

	/**
	* Default modulename
	*/
	public $name = 'PORTAL_UPCOMING';

	/**
	* Default module-image:
	* file must be in "{T_THEME_PATH}/images/portal/"
	*/
	public $image_src = 'icon_subscribe.gif';

	/**
	* module-language file
	* file must be in "language/{$user->lang}/mods/portal/"
	*/
	public $language = 'portal_upcoming_module';
	
	/**
	* custom acp template
	* file must be in "adm/style/portal/"
	*/
	public $custom_acp_tpl = '';
	
	/**
	* hide module name in ACP configuration page
	*/
	public $hide_name = false;

	
	public function get_template_side($module_id)
	{
		global $config, $template;

		$template->assign_vars(array(
			'EXAMPLE'			=> $config['board3_configname2_' . $module_id],
		));
		
				return 'upcoming_events_side.html';
	}

	public function get_template_acp($module_id)
	{
		return array(
			'title'	=> 'Upcoming Raids',
			'vars'	=> array(),
		);
	}

	/**
	* API functions
	*/
	public function install($module_id)
	{
		return true;
	}

	public function uninstall($module_id)
	{
		return true;
	}
}
And this is my block code

Code: Select all

{$LR_BLOCK_H_L}{$LR_BLOCK_H_R}
<!-- serverstatusblock -->
<div class="panel">
<div class="inner">
<span class="corners-top"><span></span></span>
		<!-- INCLUDE planner/raidplan/planner_upcoming.html -->
</div>
</div>
<!-- end serverstatus -->
{$LR_BLOCK_F_L}{$LR_BLOCK_F_R}
As you can see under my facbook block - I have managed to do that so far.

http://senilityguild.com

But as I understand it the BBDKP portal.php has all the includes. This is where I am stuck - and I do not know what to include in the above code and where. I assume I include it somewhere here"

Code: Select all

public function get_template_side($module_id)
	{
		global $config, $template;

		$template->assign_vars(array(
			'EXAMPLE'			=> $config['board3_configname2_' . $module_id],
		));
		
				return 'upcoming_events_side.html';
	}


But the how is beyond my level of PHP.

I know this is the raidplanner code in bbdkp portal.php

Code: Select all

if (isset($config['bbdkp_raidplanner']))
{	
	if ($config['rp_show_portal'] == 1)
	{
		$user->add_lang(array('mods/raidplanner'));
		if (!class_exists('rpblocks', false))
		{
			//display the blocks
			include($phpbb_root_path . 'includes/bbdkp/raidplanner/rpblocks.' . $phpEx);
		}
		$blocks = new rpblocks();
		$blocks->display();
	}
}
I know I am almost there. I just need a lil help from brainer people :-)
I would love some help on this and I really hope someone can. I didn't think it would be this complicated.

Re: New Module v2.0 to include BBDKP blocks

Posted: 13. October 2012 15:10
by Marc
You just add this code:

Code: Select all

if (isset($config['bbdkp_raidplanner']))
{   
   if ($config['rp_show_portal'] == 1)
   {
      $user->add_lang(array('mods/raidplanner'));
      if (!class_exists('rpblocks', false))
      {
         //display the blocks
         include($phpbb_root_path . 'includes/bbdkp/raidplanner/rpblocks.' . $phpEx);
      }
      $blocks = new rpblocks();
      $blocks->display();
   }
}
Right before this:

Code: Select all

return 'upcoming_events_side.html';

Re: New Module v2.0 to include BBDKP blocks

Posted: 13. October 2012 23:28
by kiwipearls
Thanks Marc.

I had tried that so many times and it failed I ened up having to do it this way:

(I know the whole point of v2 is to not edit portal.php, but for me it was the only way to get it working)
With sheer determination to get this working, I have figured it out.

You need to create the upcoming raids module.

portal/module/portal_upcoming.php

This displays the block on the right side column.

Code: Select all

<?php
/**
*
* @package Board3 Portal v2 - Upcoming
* @copyright (c) Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* @package Upcoming
*/
class portal_upcoming_module
{
	/**
	* Allowed columns: Just sum up your options (Exp: left + right = 10)
	* top		1
	* left		2
	* center	4
	* right		8
	* bottom	16
	*/
	public $columns = 8;

	/**
	* Default modulename
	*/
	public $name = 'PORTAL_UPCOMING';

	/**
	* Default module-image:
	* file must be in "{T_THEME_PATH}/images/portal/"
	*/
	public $image_src = 'icon_subscribe.gif';

	/**
	* module-language file
	* file must be in "language/{$user->lang}/mods/portal/"
	*/
	public $language = 'portal_upcoming_module';
	
	/**
	* custom acp template
	* file must be in "adm/style/portal/"
	*/
	public $custom_acp_tpl = '';
	
	/**
	* hide module name in ACP configuration page
	*/
	public $hide_name = false;

	
	public function get_template_side($module_id)
	{
		global $config, $template;

		
		
				return 'upcoming_events_side.html';
	}

	public function get_template_acp($module_id)
	{
		return array(
			'title'	=> 'Upcoming Raids',
			'vars'	=> array(),
		);
	}

	/**
	* API functions
	*/
	public function install($module_id)
	{
		return true;
	}

	public function uninstall($module_id)
	{
		return true;
	}
}
 
You then need to create the block - this is a side block

yourstyle/template/portal/modules/upcoming_events_side.html

Code: Select all

 {$LR_BLOCK_H_L}{$LR_BLOCK_H_R}
<!-- serverstatusblock -->
<div class="panel">
<div class="inner">
<span class="corners-top"><span></span></span>
		<!-- INCLUDE planner/raidplan/planner_upcoming.html -->
</div>
</div>
<!-- end serverstatus -->
{$LR_BLOCK_F_L}{$LR_BLOCK_F_R} 
You then need to use this portal.php code

Code: Select all

<?php
/**
*
* @package Board3 Portal v2
* @copyright (c) Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
define('IN_PORTAL', true);
define('IN_BBDKP', true);

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'portal/includes/constants.' . $phpEx);
$portal_root_path = PORTAL_ROOT_PATH;
include($phpbb_root_path . $portal_root_path . 'includes/functions_modules.' . $phpEx);
include($phpbb_root_path . $portal_root_path . 'includes/functions.' . $phpEx);

if(!defined("EMED_BBDKP"))
{
    trigger_error($user->lang['BBDKPDISABLED'], E_USER_WARNING); 
    
}
if (!isset($config['bbdkp_version']))
{
	// THE CONFIGS AND DATABASE TABLES AREN'T INSTALLED, EXIT
    trigger_error('GENERAL_ERROR', E_USER_WARNING); 
    
}

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/portal');
$user->setup('viewforum');
$user->add_lang(array('mods/dkp_common'));

/**
* Make sure we do an isset first, 
* else we will get errors if someone uninstalls the portal and forgets to remove portal.php
*/
if (!isset($config['board3_enable']) || !$config['board3_enable'] || !$auth->acl_get('u_view_portal'))
{
	redirect(append_sid($phpbb_root_path . 'index.' . $phpEx));
}

/**
* get initial data
*/
$portal_config = obtain_portal_config();
$portal_modules = obtain_portal_modules();

/**
* set up column_count array
* with this we can hide unneeded parts of the portal
*/
$module_count = array(
	'total' 	=> 0,
	'top'		=> 0,
	'left'		=> 0,
	'center'	=> 0,
	'right'		=> 0,
	'bottom'	=> 0,
);

/**
* start assigning block vars
*/
foreach ($portal_modules as $row)
{
	if($row['module_status'] == B3_MODULE_DISABLED)
	{
		continue;
	}
	
	$class_name = 'portal_' . $row['module_classname'] . '_module';
	if (!class_exists($class_name))
	{
		include("{$phpbb_root_path}{$portal_root_path}modules/portal_{$row['module_classname']}.$phpEx");
	}
	if (!class_exists($class_name))
	{
		trigger_error(sprintf($user->lang['CLASS_NOT_FOUND'], $class_name, 'portal_' . $row['module_classname']), E_USER_ERROR);
	}

	$module = new $class_name();
	
	/** 
	* Check for permissions before loading anything
	* the default group of a user always defines his/her permission (KISS)
	*/
	$group_ary = (!empty($row['module_group_ids'])) ? explode(',', $row['module_group_ids']) : '';
	if ((is_array($group_ary) && !in_array($user->data['group_id'], $group_ary)))
	{
		continue;
	}
	
	if ($module->language)
	{
		$user->add_lang('mods/portal/' . $module->language);
	}
	if ($row['module_column'] == column_string_num('left') && $config['board3_left_column'])
	{
		$template_module = $module->get_template_side($row['module_id']);
		$template_column = 'left';
		++$module_count['left'];
	}
	if ($row['module_column'] == column_string_num('center'))
	{
		$template_module = $module->get_template_center($row['module_id']);
		$template_column = 'center';
		++$module_count['center'];
	}
	if ($row['module_column'] == column_string_num('right') && $config['board3_right_column'])
	{
		$template_module = $module->get_template_side($row['module_id']);
		$template_column = 'right';
		++$module_count['right'];
	}
	if ($row['module_column'] == column_string_num('top'))
	{
		$template_module = $module->get_template_center($row['module_id']);
		++$module_count['top'];
	}
	if ($row['module_column'] == column_string_num('bottom'))
	{
		$template_module = $module->get_template_center($row['module_id']);
		++$module_count['bottom'];
	}
	if (!isset($template_module))
	{
		continue;
	}

	// Custom Blocks that have been defined in the ACP will return an array instead of just the name of the template file
	if (is_array($template_module))
	{
		$template->assign_block_vars('modules_' . column_num_string($row['module_column']), array(
			'TEMPLATE_FILE'			=> 'portal/modules/' . $template_module['template'],
			'IMAGE_SRC'			=> $phpbb_root_path . 'styles/' . $user->theme['theme_path'] . '/theme/images/portal/' . $template_module['image_src'],
			'TITLE'				=> $template_module['title'],
			'CODE'				=> $template_module['code'],
			'MODULE_ID'			=> $row['module_id'],
			'IMAGE_WIDTH'			=> $row['module_image_width'],
			'IMAGE_HEIGHT'			=> $row['module_image_height'],
		));
	}
	else
	{
		$template->assign_block_vars('modules_' . column_num_string($row['module_column']), array(
			'TEMPLATE_FILE'			=> 'portal/modules/' . $template_module,
			'IMAGE_SRC'			=> $phpbb_root_path . 'styles/' . $user->theme['theme_path'] . '/theme/images/portal/' . $row['module_image_src'],
			'IMAGE_WIDTH'			=> $row['module_image_width'],
			'IMAGE_HEIGHT'			=> $row['module_image_height'],
			'MODULE_ID'			=> $row['module_id'],
			'TITLE'				=> (isset($user->lang[$row['module_name']])) ? $user->lang[$row['module_name']] : utf8_normalize_nfc($row['module_name']),
		));
	}
	unset($template_module);
}
$module_count['total'] = sizeof($portal_modules);

// Redirect to index if there are currently no active modules
if($module_count['total'] < 1)
{
	redirect(append_sid($phpbb_root_path . 'index.' . $phpEx));
}

// Assign specific vars
$template->assign_vars(array(
// 	'S_SMALL_BLOCK'			=> true,
	'S_PORTAL_LEFT_COLUMN'	=> $config['board3_left_column_width'],
	'S_PORTAL_RIGHT_COLUMN'	=> $config['board3_right_column_width'],
	'S_LEFT_COLUMN'			=> ($module_count['left'] > 0 && $config['board3_left_column']) ? true : false,
	'S_CENTER_COLUMN'		=> ($module_count['center'] > 0) ? true : false,
	'S_RIGHT_COLUMN'		=> ($module_count['right'] > 0 && $config['board3_right_column']) ? true : false,
	'S_TOP_COLUMN'			=> ($module_count['top'] > 0) ? true : false,
	'S_BOTTOM_COLUMN'		=> ($module_count['bottom'] > 0) ? true : false,
	'S_DISPLAY_PHPBB_MENU'	=> $config['board3_phpbb_menu'],
	'B3P_DISPLAY_JUMPBOX'	=> $config['board3_display_jumpbox'],
));

if (isset($config['bbdkp_raidplanner']))
{	
	if ($config['rp_show_portal'] == 1)
	{
		$user->add_lang(array('mods/raidplanner'));
		if (!class_exists('rpblocks', false))
		{
			//display the blocks
			include($phpbb_root_path . 'includes/bbdkp/raidplanner/rpblocks.' . $phpEx);
		}
		$blocks = new rpblocks();
		$blocks->display();
	}
}

// Output page
page_header($user->lang['PORTAL']);

$template->set_filenames(array(
	'body' => 'portal/portal_body.html')
);

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

page_footer();
 
Breakdown of my portal.php edits

Find

Code: Select all

 define('IN_PORTAL', true);
add after

Code: Select all

define('IN_BBDKP', true); 
Find

Code: Select all

// Start session management 
add before

Code: Select all

if(!defined("EMED_BBDKP"))
{
    trigger_error($user->lang['BBDKPDISABLED'], E_USER_WARNING); 
    
}
if (!isset($config['bbdkp_version']))
{
	// THE CONFIGS AND DATABASE TABLES AREN'T INSTALLED, EXIT
    trigger_error('GENERAL_ERROR', E_USER_WARNING); 
    
} 
Find

Code: Select all

 $user->setup('mods/portal');
add after

Code: Select all

 $user->setup('viewforum');
$user->add_lang(array('mods/dkp_common'));  
Find

Code: Select all

 // Output page 
Add before

Code: Select all

 if (isset($config['bbdkp_raidplanner']))
{	
	if ($config['rp_show_portal'] == 1)
	{
		$user->add_lang(array('mods/raidplanner'));
		if (!class_exists('rpblocks', false))
		{
			//display the blocks
			include($phpbb_root_path . 'includes/bbdkp/raidplanner/rpblocks.' . $phpEx);
		}
		$blocks = new rpblocks();
		$blocks->display();
	}
}
You also need to define the language file:

language/en/mods/portall/portal_upcoming_module.php

Code: Select all

 <?php
/**
*
* @package Board3 Portal v2 - Welcome
* @copyright (c) Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* DO NOT CHANGE
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

if (empty($lang) || !is_array($lang))
{
	$lang = array();
}

// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
$lang = array_merge($lang, array(
	'PORTAL_UPCOMING'		=> 'Upcoming Raids',
	
));
Hoepfully this helps others who swtich over to Board 3 version 2.0+