Merge pull request #185 from marc1706/feature/module_services

[feature/module_services] Start using services for modules
This commit is contained in:
Marc Alexander
2013-11-10 04:26:09 -08:00
32 changed files with 416 additions and 39 deletions

View File

@@ -21,6 +21,7 @@ services:
- @path_helper
- %core.root_path%
- .%core.php_ext%
- @board3.module_collection
board3.version.check:
class: \board3\portal\includes\mod_version_check
@@ -31,3 +32,22 @@ services:
- %core.php_ext%
- @template
- @user
board3.module_collection:
class: phpbb\di\service_collection
arguments:
- @service_container
tags:
- { name: service_collection, tag: board3.module }
board3.module.stylechanger:
class: \board3\portal\modules\stylechanger
arguments:
- @config
- @template
- @dbal.conn
- %core.php_ext%
- %core.root_path%
- @user
tags:
- { name: board3.module }

View File

@@ -65,6 +65,12 @@ class main
*/
protected $path_helper;
/**
* Board3 Modules service collection
* @var phpbb\di\service_collection
*/
protected $modules;
/**
* Constructor
* NOTE: The parameters of this method must match in order and type with
@@ -76,8 +82,10 @@ class main
* @param \phpbb\path_helper $path_helper phpBB path helper
* @param string $phpbb_root_path phpBB root path
* @param string $php_ext PHP file extension
* @param \phpbb\di\service_collection $modules Board3 Modules service
* collection
*/
public function __construct($auth, $config, $template, $user, $path_helper, $phpbb_root_path, $php_ext)
public function __construct($auth, $config, $template, $user, $path_helper, $phpbb_root_path, $php_ext, $modules)
{
global $portal_root_path;
@@ -88,6 +96,8 @@ class main
$this->path_helper = $path_helper;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->register_modules($modules);
$this->includes_path = $phpbb_root_path . 'ext/board3/portal/portal/';
$this->root_path = $phpbb_root_path . 'ext/board3/portal/';
$portal_root_path = $this->root_path;
@@ -100,6 +110,25 @@ class main
}
}
/**
* Register list of Board3 Portal modules
*
* @param \phpbb\di\service_collection $modules Board3 Modules service
* collection
* @return void
*/
protected function register_modules($modules)
{
foreach ($modules as $current_module)
{
$class_name = '\\' . get_class($current_module);
if (!isset($this->modules[$class_name]))
{
$this->modules[$class_name] = $current_module;
}
}
}
/**
* Extension front handler method. This is called automatically when your extension is accessed
* through index.php?ext=example/foobar
@@ -145,17 +174,28 @@ class main
continue;
}
$class_name = 'portal_' . $row['module_classname'] . '_module';
if (!class_exists($class_name))
// Do not try to load non-existant modules
if (!isset($this->modules[$row['module_classname']]))
{
include("{$this->includes_path}modules/portal_{$row['module_classname']}{$this->php_ext}");
}
if (!class_exists($class_name))
{
trigger_error(sprintf($this->user->lang['CLASS_NOT_FOUND'], $class_name, 'portal_' . $row['module_classname']), E_USER_ERROR);
}
if (file_exists("{$this->includes_path}modules/portal_{$row['module_classname']}{$this->php_ext}"))
{
include("{$this->includes_path}modules/portal_{$row['module_classname']}{$this->php_ext}");
}
$module = new $class_name();
$class_name = 'portal_' . $row['module_classname'] . '_module';
if (class_exists($class_name))
{
$module = new $class_name();
}
else
{
continue;
}
}
else
{
$module = $this->modules[$row['module_classname']];
}
/**
* Check for permissions before loading anything
@@ -167,9 +207,9 @@ class main
continue;
}
if ($module->language)
if ($language_file = $module->get_language())
{
$this->user->add_lang_ext('board3/portal', 'mods/portal/' . $module->language);
$this->user->add_lang_ext('board3/portal', 'mods/portal/' . $language_file);
}
if ($row['module_column'] == column_string_num('left') && $this->config['board3_left_column'])
{

96
modules/module_base.php Normal file
View File

@@ -0,0 +1,96 @@
<?php
/**
*
* @package Board3 Portal v2.1
* @copyright (c) 2013 Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
namespace board3\portal\modules;
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* @package module_base
*/
class module_base implements module_interface
{
/**
* @inheritdoc
*/
public function get_allowed_columns()
{
return $this->columns;
}
/**
* @inheritdoc
*/
public function get_name()
{
return $this->name;
}
/**
* @inheritdoc
*/
public function get_image()
{
return $this->image_src;
}
/**
* @inheritdoc
*/
public function get_language()
{
return $this->language;
}
/**
* @inheritdoc
*/
public function get_template_side($module_id)
{
return;
}
/**
* @inheritdoc
*/
public function get_template_center($module_id)
{
return;
}
/**
* @inheritdoc
*/
public function get_template_acp($module_id)
{
return false;
}
/**
* @inheritdoc
*/
public function install($module_id)
{
return true;
}
/**
* @inheritdoc
*/
public function uninstall($module_id)
{
return true;
}
}

View File

@@ -0,0 +1,108 @@
<?php
/**
*
* @package Board3 Portal v2.1
* @copyright (c) 2013 Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
namespace board3\portal\modules;
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* @package module_interface
*/
interface module_interface
{
/**
* Get allowed columns
* Allowed columns: Just sum up your options (Exp: left + right = 10)
* top 1
* left 2
* center 4
* right 8
* bottom 16
*
* @return int Allowed columns
*/
public function get_allowed_columns();
/**
* Get module name
*
* @return string Module name, e.g. BOARD3_NEWS
*/
public function get_name();
/**
* Get default module image:
* file must be in "{T_THEME_PATH}/images/portal/"
*
* @return string Module image file
*/
public function get_image();
/**
* Get module language file
* File must be in "board3/portal/language/{$user->lang}/portal/" or
* this should return false.
*
* @return string|bool Language file or false
*/
public function get_language();
/**
* Get template file for side columns
*
* @param int $module_id Module's ID
*
* @return string Module template file
*/
public function get_template_side($module_id);
/**
* Get template file for center columns
*
* @param int $module_id Module's ID
*
* @return string Module template file
*/
public function get_template_center($module_id);
/**
* Get acp settings
*
* @param int $module_id Module's ID
*
* @return array ACP settings for module
*/
public function get_template_acp($module_id);
/**
* Install module
* Executes any additional commands for installing the module
*
* @param int $module_id Module's ID
*
* @return bool True if install was successful, false if not
*/
public function install($module_id);
/**
* Uninstall module
* Executes any additional commands for uninstalling the module
*
* @param int $module_id Module's ID
*
* @return bool True if uninstall was successful, false if not
*/
public function uninstall($module_id);
}

113
modules/stylechanger.php Normal file
View File

@@ -0,0 +1,113 @@
<?php
/**
*
* @package Board3 Portal v2.1
* @copyright (c) Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
namespace board3\portal\modules;
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* @package Stylechanger
*/
class stylechanger extends module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)
* top 1
* left 2
* center 4
* right 8
* bottom 16
*/
public $columns = 10;
/**
* Default modulename
*/
public $name = 'BOARD_STYLE';
/**
* Default module-image:
* file must be in "{T_THEME_PATH}/images/portal/"
*/
public $image_src = 'portal_style.png';
/**
* module-language file
* file must be in "language/{$user->lang}/mods/portal/"
*/
public $language = 'portal_stylechanger_module';
public function __construct($config, $template, $db, $phpEx, $phpbb_root_path, $user)
{
$this->config = $config;
$this->template = $template;
$this->db = $db;
$this->php_ext = $phpEx;
$this->phpbb_root_path = $phpbb_root_path;
$this->user = $user;
}
/**
* @inheritdoc
*/
public function get_template_side($module_id)
{
$style_count = 0;
$style_select = '';
$sql = 'SELECT style_id, style_name
FROM ' . STYLES_TABLE . '
WHERE style_active = 1
ORDER BY LOWER(style_name) ASC';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$style = request_var('style', 0);
if (!empty($style))
{
$url = str_replace('style=' . $style, 'style=' . $row['style_id'], append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"));
}
else
{
$url = append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", 'style=' . $row['style_id']);
}
++$style_count;
$style_select .= '<option value="' . $url . '"' . ($row['style_id'] == $this->user->style['style_id'] ? ' selected="selected"' : '') . '>' . htmlspecialchars($row['style_name']) . '</option>';
}
$this->db->sql_freeresult($result);
if(strlen($style_select))
{
$this->template->assign_var('STYLE_SELECT', $style_select);
}
// Assign specific vars
$this->template->assign_vars(array(
'S_STYLE_OPTIONS' => ($this->config['override_user_style'] || $style_count < 2) ? '' : style_select($this->user->data['user_style']),
));
return 'stylechanger_side.html';
}
/**
* @inheritdoc
*/
public function get_template_acp($module_id)
{
return array(
'title' => 'BOARD_STYLE',
'vars' => array(),
);
}
}

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Modulname
*/
class portal_announcements_module
class portal_announcements_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Modulname
*/
class portal_attachments_module
class portal_attachments_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Birthday List
*/
class portal_birthday_list_module
class portal_birthday_list_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Calendar
*/
class portal_calendar_module
class portal_calendar_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Clock
*/
class portal_clock_module
class portal_clock_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Custom
*/
class portal_custom_module
class portal_custom_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Modulname
*/
class portal_modulename_module
class portal_modulename_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Donation
*/
class portal_donation_module
class portal_donation_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Forumlist
*/
class portal_forumlist_module
class portal_forumlist_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Friends
*/
class portal_friends_module
class portal_friends_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Latest Bots
*/
class portal_latest_bots_module
class portal_latest_bots_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Modulname
*/
class portal_latest_members_module
class portal_latest_members_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Leaders
*/
class portal_leaders_module
class portal_leaders_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Clock
*/
class portal_link_us_module
class portal_link_us_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Links
*/
class portal_links_module
class portal_links_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Main Menu
*/
class portal_main_menu_module
class portal_main_menu_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package News
*/
class portal_news_module
class portal_news_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Poll
*/
class portal_poll_module
class portal_poll_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Random Member
*/
class portal_random_member_module
class portal_random_member_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Recent
*/
class portal_recent_module
class portal_recent_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Search
*/
class portal_search_module
class portal_search_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Statistics
*/
class portal_statistics_module
class portal_statistics_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Stylechanger
*/
class portal_stylechanger_module
class portal_stylechanger_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Topposters
*/
class portal_topposters_module
class portal_topposters_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Modulname
*/
class portal_user_menu_module
class portal_user_menu_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Welcome
*/
class portal_welcome_module
class portal_welcome_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)

View File

@@ -18,7 +18,7 @@ if (!defined('IN_PHPBB'))
/**
* @package Who is online
*/
class portal_whois_online_module
class portal_whois_online_module extends \board3\portal\modules\module_base
{
/**
* Allowed columns: Just sum up your options (Exp: left + right = 10)