[feature/module_services] Move welcome module to module services

This commit is contained in:
Marc Alexander
2013-11-17 01:38:11 +01:00
parent 12db763560
commit 06bc28ed5a
5 changed files with 123 additions and 77 deletions

View File

@@ -53,8 +53,8 @@ var help_line = {
<!-- END custom_tags --> <!-- END custom_tags -->
} }
function change_palette() function change_palette()
{ {
dE('colour_palette'); dE('colour_palette');
e = document.getElementById('colour_palette'); e = document.getElementById('colour_palette');
@@ -66,7 +66,7 @@ var help_line = {
{ {
document.getElementById('bbpalette').value = '{LA_FONT_COLOR}'; document.getElementById('bbpalette').value = '{LA_FONT_COLOR}';
} }
} }
// ]]> // ]]>
</script> </script>

View File

@@ -1,6 +1,6 @@
<!-- INCLUDE overall_header.html --> <!-- INCLUDE overall_header.html -->
<script type="text/javascript" src="{B3P_ACP_ROOT}adm/style/portal/acp_portal.js"></script> <!-- INCLUDEJS portal/acp_portal.js -->
<script type="text/javascript"> <script type="text/javascript">
// <![CDATA[ // <![CDATA[
/** /**
@@ -53,6 +53,21 @@ var help_line = {
<!-- END custom_tags --> <!-- END custom_tags -->
} }
function change_palette()
{
dE('colour_palette');
e = document.getElementById('colour_palette');
if (e.style.display == 'block')
{
document.getElementById('bbpalette').value = '{LA_FONT_COLOR_HIDE}';
}
else
{
document.getElementById('bbpalette').value = '{LA_FONT_COLOR}';
}
}
// ]]> // ]]>
</script> </script>
@@ -134,38 +149,12 @@ var help_line = {
<dd> <dd>
<div id="colour_palette" style="display: none;"> <div id="colour_palette" style="display: none;">
<dl style="clear: left;"> <dl style="clear: left;">
<dt style="border: none;"><label>{L_FONT_COLOR}:</label><br /></dt> <dt style="border: none;"><label>{L_FONT_COLOR}{L_COLON}</label></dt>
<dd></dd>
</dl> </dl>
<dl style="clear: left;"> <dl style="clear: left;">
<dt style="border: none;"> <dt id="color_palette_placeholder" style="border: none;"></dt>
<script type="text/javascript"> <dd></dd>
// <![CDATA[
function change_palette()
{
e = document.getElementById('colour_palette');
if(e.style.display == 'block')
{
dE('colour_palette', -1);
}
else
{
dE('colour_palette', 1);
}
if (e.style.display == 'block')
{
document.getElementById('bbpalette').value = '{LA_FONT_COLOR_HIDE}';
}
else
{
document.getElementById('bbpalette').value = '{LA_FONT_COLOR}';
}
}
colorPalette('h', 10, 5);
// ]]>
</script>
</dt>
</dl> </dl>
</div> </div>
<div id="format-buttons"> <div id="format-buttons">

View File

@@ -308,3 +308,14 @@ services:
- %core.php_ext% - %core.php_ext%
tags: tags:
- { name: board3.module } - { name: board3.module }
board3.module.welcome:
class: \board3\portal\modules\welcome
arguments:
- @config
- @template
- @user
- %core.root_path%
- %core.php_ext%
tags:
- { name: board3.module }

View File

@@ -402,7 +402,7 @@ class v210_beta1 extends \phpbb\db\migration\migration
'module_status' => 1, 'module_status' => 1,
), ),
array( array(
'module_classname' => 'welcome', 'module_classname' => '\board3\portal\modules\welcome',
'module_column' => 2, 'module_column' => 2,
'module_order' => 1, 'module_order' => 1,
'module_name' => 'PORTAL_WELCOME', 'module_name' => 'PORTAL_WELCOME',

View File

@@ -1,24 +1,18 @@
<?php <?php
/** /**
* *
* @package Board3 Portal v2 - Welcome * @package Board3 Portal v2.1
* @copyright (c) Board3 Group ( www.board3.de ) * @copyright (c) Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* *
*/ */
/** namespace board3\portal\modules;
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/** /**
* @package Welcome * @package Welcome
*/ */
class portal_welcome_module extends \board3\portal\modules\module_base class welcome extends module_base
{ {
/** /**
* Allowed columns: Just sum up your options (Exp: left + right = 10) * Allowed columns: Just sum up your options (Exp: left + right = 10)
@@ -53,23 +47,62 @@ class portal_welcome_module extends \board3\portal\modules\module_base
*/ */
public $custom_acp_tpl = 'acp_portal_welcome'; public $custom_acp_tpl = 'acp_portal_welcome';
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\template */
protected $template;
/** @var \phpbb\user */
protected $user;
/** @var php file extension */
protected $php_ext;
/** @var phpbb root path */
protected $phpbb_root_path;
/**
* Construct a welcome object
*
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\template $template phpBB template
* @param \phpbb\user $user phpBB user
* @param string $phpbb_root_path phpBB root path
* @param string $phpEx php file extension
*/
public function __construct($config, $template, $user, $phpbb_root_path, $phpEx)
{
$this->config = $config;
$this->template = $template;
$this->user = $user;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
}
/**
* @inheritdoc
*/
public function get_template_center($module_id) public function get_template_center($module_id)
{ {
global $config, $template, $portal_config, $phpEx; $portal_config = obtain_portal_config();
// Generate text for display and assign template vars // Generate text for display and assign template vars
$uid = $config['board3_welcome_message_uid_' . $module_id]; $uid = $this->config['board3_welcome_message_uid_' . $module_id];
$bitfield = $config['board3_welcome_message_bitfield_' . $module_id]; $bitfield = $this->config['board3_welcome_message_bitfield_' . $module_id];
$bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS; $bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
$text = generate_text_for_display($portal_config['board3_welcome_message_' . $module_id], $uid, $bitfield, $bbcode_options); $text = generate_text_for_display($portal_config['board3_welcome_message_' . $module_id], $uid, $bitfield, $bbcode_options);
$template->assign_vars(array( $this->template->assign_vars(array(
'PORTAL_WELCOME_MSG' => $text, 'PORTAL_WELCOME_MSG' => $text,
)); ));
return 'welcome_center.html'; return 'welcome_center.html';
} }
/**
* @inheritdoc
*/
public function get_template_acp($module_id) public function get_template_acp($module_id)
{ {
return array( return array(
@@ -82,7 +115,7 @@ class portal_welcome_module extends \board3\portal\modules\module_base
} }
/** /**
* API functions * @inheritdoc
*/ */
public function install($module_id) public function install($module_id)
{ {
@@ -93,6 +126,9 @@ class portal_welcome_module extends \board3\portal\modules\module_base
return true; return true;
} }
/**
* @inheritdoc
*/
public function uninstall($module_id, $db) public function uninstall($module_id, $db)
{ {
$del_config = array( $del_config = array(
@@ -113,17 +149,24 @@ class portal_welcome_module extends \board3\portal\modules\module_base
return ((!$check) ? $check : $db->sql_query($sql)); // if something went wrong, make sure we are aware of the first query return ((!$check) ? $check : $db->sql_query($sql)); // if something went wrong, make sure we are aware of the first query
} }
/**
* Manage welcome message
*
* @param mixed $value Value of input
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function manage_welcome($value, $key, $module_id) public function manage_welcome($value, $key, $module_id)
{ {
global $db, $portal_config, $config, $template, $user, $phpEx, $phpbb_admin_path, $phpbb_root_path;
$action = (isset($_POST['reset'])) ? 'reset' : ''; $action = (isset($_POST['reset'])) ? 'reset' : '';
$action = (isset($_POST['submit'])) ? 'save' : $action; $action = (isset($_POST['submit'])) ? 'save' : $action;
$action = (isset($_POST['preview'])) ? 'preview' : $action; $action = (isset($_POST['preview'])) ? 'preview' : $action;
$portal_config = obtain_portal_config(); $portal_config = obtain_portal_config();
$u_action = append_sid($phpbb_admin_path . 'index.' . $phpEx, 'i=portal&amp;mode=config&amp;module_id=' . $module_id); $u_action = append_sid('index.' . $this->php_ext, 'i=\board3\portal\acp\portal_module&amp;mode=config&amp;module_id=' . $module_id);
switch($action) switch($action)
{ {
@@ -131,7 +174,7 @@ class portal_welcome_module extends \board3\portal\modules\module_base
case 'save': case 'save':
if (!check_form_key('acp_portal')) if (!check_form_key('acp_portal'))
{ {
trigger_error($user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING); trigger_error($this->user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
} }
$welcome_message = utf8_normalize_nfc(request_var('welcome_message', '', true)); $welcome_message = utf8_normalize_nfc(request_var('welcome_message', '', true));
@@ -142,10 +185,10 @@ class portal_welcome_module extends \board3\portal\modules\module_base
// first check for obvious errors, we don't want to waste server resources // first check for obvious errors, we don't want to waste server resources
if(empty($welcome_message)) if(empty($welcome_message))
{ {
trigger_error($user->lang['ACP_PORTAL_WELCOME_MESSAGE_SHORT']. adm_back_link($u_action), E_USER_WARNING); trigger_error($this->user->lang['ACP_PORTAL_WELCOME_MESSAGE_SHORT']. adm_back_link($u_action), E_USER_WARNING);
} }
add_log('admin', 'LOG_PORTAL_CONFIG', $user->lang['PORTAL_WELCOME']); add_log('admin', 'LOG_PORTAL_CONFIG', $this->user->lang['PORTAL_WELCOME']);
// set_portal_config will take care of escaping the welcome message // set_portal_config will take care of escaping the welcome message
set_portal_config('board3_welcome_message_' . $module_id, $welcome_message); set_portal_config('board3_welcome_message_' . $module_id, $welcome_message);
@@ -156,20 +199,15 @@ class portal_welcome_module extends \board3\portal\modules\module_base
case 'preview': case 'preview':
$welcome_message = $text = utf8_normalize_nfc(request_var('welcome_message', '', true)); $welcome_message = $text = utf8_normalize_nfc(request_var('welcome_message', '', true));
if (!class_exists('parse_message'))
{
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
}
$bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS; $bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
$uid = (isset($config['board3_welcome_message_uid_' . $module_id])) ? $config['board3_welcome_message_uid_' . $module_id] : ''; $uid = (isset($this->config['board3_welcome_message_uid_' . $module_id])) ? $this->config['board3_welcome_message_uid_' . $module_id] : '';
$bitfield = (isset($config['board3_welcome_message_bitfield_' . $module_id])) ? $config['board3_welcome_message_bitfield_' . $module_id] : ''; $bitfield = (isset($this->config['board3_welcome_message_bitfield_' . $module_id])) ? $this->config['board3_welcome_message_bitfield_' . $module_id] : '';
$options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS; $options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS;
generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true); generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true);
$text = generate_text_for_display($text, $uid, $bitfield, $options); $text = generate_text_for_display($text, $uid, $bitfield, $options);
$template->assign_vars(array( $this->template->assign_vars(array(
'PREVIEW_TEXT' => $text, 'PREVIEW_TEXT' => $text,
'S_PREVIEW' => true, 'S_PREVIEW' => true,
)); ));
@@ -179,10 +217,10 @@ class portal_welcome_module extends \board3\portal\modules\module_base
default: default:
if(!isset($welcome_message)) if(!isset($welcome_message))
{ {
$welcome_message = generate_text_for_edit($portal_config['board3_welcome_message_' . $module_id], $config['board3_welcome_message_uid_' . $module_id], ''); $welcome_message = generate_text_for_edit($portal_config['board3_welcome_message_' . $module_id], $this->config['board3_welcome_message_uid_' . $module_id], '');
} }
$template->assign_vars(array( $this->template->assign_vars(array(
'WELCOME_MESSAGE' => (is_array($welcome_message)) ? $welcome_message['text'] : $welcome_message, 'WELCOME_MESSAGE' => (is_array($welcome_message)) ? $welcome_message['text'] : $welcome_message,
//'U_BACK' => $u_action, //'U_BACK' => $u_action,
'U_ACTION' => $u_action, 'U_ACTION' => $u_action,
@@ -192,22 +230,30 @@ class portal_welcome_module extends \board3\portal\modules\module_base
'S_BBCODE_FLASH' => true, 'S_BBCODE_FLASH' => true,
'S_BBCODE_QUOTE' => true, 'S_BBCODE_QUOTE' => true,
'S_BBCODE_ALLOWED' => true, 'S_BBCODE_ALLOWED' => true,
'MAX_FONT_SIZE' => (int) $config['max_post_font_size'], 'MAX_FONT_SIZE' => (int) $this->config['max_post_font_size'],
)); ));
if(!function_exists('display_forums')) if(!function_exists('display_forums'))
{ {
include($phpbb_root_path . 'includes/functions_display.' . $phpEx); include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
} }
// Build custom bbcodes array // Build custom bbcodes array
display_custom_bbcodes(); display_custom_bbcodes();
$user->add_lang('posting'); $this->user->add_lang('posting');
break; break;
} }
} }
/**
* Update welcome message
*
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function update_welcome($key, $module_id) public function update_welcome($key, $module_id)
{ {
$this->manage_welcome('', $key, $module_id); $this->manage_welcome('', $key, $module_id);