[feature/module_services] Start using services for modules

This includes a module_interface and module_base for the modules.
Adding, moving, or managing modules doesn't work yet.
This commit is contained in:
Marc Alexander
2013-11-07 17:33:59 +01:00
parent 6df924ff0f
commit e3220460a9
5 changed files with 341 additions and 10 deletions

72
modules/module_base.php Normal file
View File

@@ -0,0 +1,72 @@
<?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
*/
abstract 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 install($module_id)
{
return true;
}
/**
* @inheritdoc
*/
public function uninstall($module_id)
{
return true;
}
}

View File

@@ -0,0 +1,99 @@
<?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 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(),
);
}
}