Merge pull request #238 from marc1706/ticket/102

[ticket/102] Ajaxify certain actions in the ACP
This commit is contained in:
Marc Alexander
2014-04-08 20:41:58 +02:00
19 changed files with 721 additions and 49 deletions

1
.gitattributes vendored
View File

@@ -6,3 +6,4 @@ travis/ export-ignore
.travis.yml export-ignore
phpunit.xml.* export-ignore
README.md export-ignore
git-tools/ export-ignore

View File

@@ -313,7 +313,7 @@ class portal_module
'S_ERROR' => (sizeof($error)) ? true : false,
'ERROR_MSG' => implode('<br />', $error),
'U_ACTION' => $this->u_action . (($module_id) ? '&amp;module_id=' . $module_id : ''),
'B3P_U_ACTION' => $this->get_module_link('config', $module_id),
'B3P_ACP_ROOT' => $this->root_path,
));
@@ -671,7 +671,7 @@ class portal_module
'MODULE_IMAGE' => ($row['module_image_src']) ? '<img src="' . $this->root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/' . $row['module_image_src'] . '" alt="' . $row['module_name'] . '" />' : '',
'MODULE_ENABLED' => ($row['module_status']) ? true : false,
'U_DELETE' => $this->u_action . '&amp;module_id=' . $row['module_id'] . '&amp;module_classname=' . $row['module_classname'] . '&amp;action=delete',
'U_DELETE' => $this->get_module_link('modules', $row['module_id']) . '&amp;action=delete&amp;module_classname=' . $row['module_classname'],
'U_EDIT' => $this->get_module_link('config', $row['module_id']),
'U_MOVE_UP' => $this->u_action . '&amp;module_id=' . $row['module_id'] . '&amp;action=move_up',
'U_MOVE_DOWN' => $this->u_action . '&amp;module_id=' . $row['module_id'] . '&amp;action=move_down',
@@ -841,6 +841,12 @@ class portal_module
}
$this->cache->destroy('portal_modules');
if ($this->request->is_ajax())
{
$json_response = new \phpbb\json_response;
$json_response->send(array('success' => true));
}
redirect($this->u_action); // redirect in order to get rid of excessive URL parameters
}
@@ -874,6 +880,7 @@ class portal_module
*/
public function move_module_up($module_id)
{
$updated = false;
$module_data = $this->get_move_module_data($module_id);
if (($module_data !== false) && ($module_data['module_order'] > 1))
@@ -904,6 +911,7 @@ class portal_module
*/
public function move_module_down($module_id)
{
$updated = false;
$module_data = $this->get_move_module_data($module_id);
if ($module_data !== false && $this->get_last_module_order($module_data['module_column']) != $module_data['module_order'])
@@ -1159,6 +1167,15 @@ class portal_module
$this->cache->purge(); // make sure we don't get errors after re-adding a module
if ($this->request->is_ajax())
{
$json_response = new \phpbb\json_response;
$json_response->send(array(
'success' => true,
'MESSAGE_TITLE' => $this->user->lang['INFORMATION'],
'MESSAGE_TEXT' => $this->user->lang['SUCCESS_DELETE'],
));
}
trigger_error($this->user->lang['SUCCESS_DELETE'] . adm_back_link($this->u_action));
}
else
@@ -1191,7 +1208,7 @@ class portal_module
*/
protected function get_module_link($mode, $module_id)
{
return preg_replace(array('/i=[0-9]+/', '/mode=[a-zA-Z0-9_]+/'), array('i=\\' . __CLASS__, 'mode=' . $mode), $this->u_action) . '&amp;module_id=' . $module_id;
return preg_replace(array('/i=[0-9]+/', '/mode=[a-zA-Z0-9_]+/'), array('i=%5C' . str_replace('\\', '%5C', __CLASS__), 'mode=' . $mode), $this->u_action) . (($module_id) ? '&amp;module_id=' . $module_id : '');
}
/**

View File

@@ -436,4 +436,4 @@ function getCaretPosition(txtarea)
}
return caretPos;
}
}

View File

@@ -14,7 +14,7 @@
<!-- ENDIF -->
<!-- IF S_EDIT -->
<form id="acp_portal_links" method="post" action="{U_ACTION}">
<form id="acp_portal_links" method="post" action="{B3P_U_ACTION}">
<fieldset>
<legend>{L_ACP_PORTAL_EVENTS}</legend>
@@ -43,8 +43,8 @@
<dl>
<dt><label for="event_all_day">{L_EVENT_ALL_DAY}:</label></dt>
<dd>
<label><input onchange="dE('end', -1)" type="radio" class="radio" name="event_all_day" value="1" id="event_all_day"<!-- IF EVENT_ALL_DAY --> checked="checked"<!-- ENDIF --> />{L_YES}</label>
<label><input onchange="dE('end', 1)" type="radio" class="radio" name="event_all_day" value="0"<!-- IF not EVENT_ALL_DAY --> checked="checked"<!-- ENDIF --> /> {L_NO}</label>
<label><input onchange="phpbb.toggleDisplay('end', -1)" type="radio" class="radio" name="event_all_day" value="1" id="event_all_day"<!-- IF EVENT_ALL_DAY --> checked="checked"<!-- ENDIF --> />{L_YES}</label>
<label><input onchange="phpbb.toggleDisplay('end', 1)" type="radio" class="radio" name="event_all_day" value="0"<!-- IF not EVENT_ALL_DAY --> checked="checked"<!-- ENDIF --> /> {L_NO}</label>
</dd>
</dl>
<div id="end"<!-- IF EVENT_ALL_DAY -->style="display: none;"<!-- ENDIF -->>

View File

@@ -38,7 +38,7 @@
<!-- ENDIF -->
</fieldset>
<!-- END mods -->
<form id="acp_portal_config" method="post" action="{U_ACTION}">
<form id="acp_portal_config" method="post" action="{B3P_U_ACTION}">
<!-- IF SHOW_MODULE_OPTIONS -->
<fieldset>
<legend>{L_MODULE_OPTIONS}</legend>

View File

@@ -1,6 +1,6 @@
<!-- INCLUDE overall_header.html -->
<!-- INCLUDEJS portal/acp_portal.js -->
<!-- INCLUDEJS portal/acp_editor.js -->
<script type="text/javascript">
// <![CDATA[
/**
@@ -55,7 +55,7 @@ var help_line = {
function change_palette()
{
dE('colour_palette');
phpbb.toggleDisplay('colour_palette');
e = document.getElementById('colour_palette');
if (e.style.display == 'block')
@@ -83,7 +83,7 @@ function change_palette()
<p>{ERROR_MSG}</p>
</div>
<!-- ENDIF -->
<form id="acp_portal_config" method="post" action="{U_ACTION}">
<form id="acp_portal_config" method="post" action="{B3P_U_ACTION}">
<!-- IF SHOW_MODULE_OPTIONS -->
<fieldset>
<legend>{L_MODULE_OPTIONS}</legend>
@@ -209,8 +209,8 @@ function change_palette()
<span>{L_ACP_PORTAL_CUSTOM_BBCODE_EXP}</span>
</dt>
<dd>
<label><input onchange="dE('bbcode-buttons', 1)" class="radio" type="radio" value="1" name="custom_use_bbcode" id="custom_use_bbcode"<!-- IF CUSTOM_USE_BBCODE --> checked="checked"<!-- ENDIF --> />{L_YES}</label>
<label><input onchange="dE('bbcode-buttons', -1)" class="radio" type="radio" value="0" name="custom_use_bbcode"<!-- IF not CUSTOM_USE_BBCODE --> checked="checked"<!-- ENDIF --> />{L_NO}</label>
<label><input onchange="phpbb.toggleDisplay('bbcode-buttons', 1)" class="radio" type="radio" value="1" name="custom_use_bbcode" id="custom_use_bbcode"<!-- IF CUSTOM_USE_BBCODE --> checked="checked"<!-- ENDIF --> />{L_YES}</label>
<label><input onchange="phpbb.toggleDisplay('bbcode-buttons', -1)" class="radio" type="radio" value="0" name="custom_use_bbcode"<!-- IF not CUSTOM_USE_BBCODE --> checked="checked"<!-- ENDIF --> />{L_NO}</label>
</dd>
</dl>
<!-- IF S_AUTH -->

View File

@@ -14,7 +14,7 @@
<!-- ENDIF -->
<!-- IF S_EDIT -->
<form id="acp_portal_links" method="post" action="{U_ACTION}">
<form id="acp_portal_links" method="post" action="{B3P_U_ACTION}">
<fieldset>
<legend>{L_ACP_PORTAL_LINKS}</legend>

View File

@@ -14,7 +14,7 @@
<!-- ENDIF -->
<!-- IF S_EDIT -->
<form id="acp_portal_links" method="post" action="{U_ACTION}">
<form id="acp_portal_links" method="post" action="{B3P_U_ACTION}">
<fieldset>
<legend>{L_ACP_PORTAL_MENU_LINK_SETTINGS}</legend>
@@ -24,8 +24,8 @@
</dl>
<dl>
<dt><label for="link_is_cat">{L_ACP_PORTAL_MENU_IS_CAT}:</label></dt>
<dd><label><input onchange="dE('url', -1)" type="radio" class="radio" name="link_is_cat" value="1" id="link_is_cat"<!-- IF S_LINK_IS_CAT --> checked="checked"<!-- ENDIF --> />{L_YES}</label>
<label><input onchange="dE('url', 1)" type="radio" class="radio" name="link_is_cat" value="0"<!-- IF not S_LINK_IS_CAT --> checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
<dd><label><input onchange="phpbb.toggleDisplay('url', -1)" type="radio" class="radio" name="link_is_cat" value="1" id="link_is_cat"<!-- IF S_LINK_IS_CAT --> checked="checked"<!-- ENDIF --> />{L_YES}</label>
<label><input onchange="phpbb.toggleDisplay('url', 1)" type="radio" class="radio" name="link_is_cat" value="0"<!-- IF not S_LINK_IS_CAT --> checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
</dl>
<div id="url"<!-- IF S_LINK_IS_CAT --> style="display: none;"<!-- ENDIF -->>
<dl>

View File

@@ -15,6 +15,7 @@
</form>
<!-- ELSE -->
<!-- INCLUDECSS portal/b3p_admin.css -->
<!-- INCLUDE overall_header.html -->
<a name="maincontent"></a>
@@ -24,7 +25,7 @@
<h1>{L_ACP_PORTAL_MODULES}</h1>
<p>{L_ACP_PORTAL_MODULES_EXP}</p>
<form id="acp_portal_modules" method="post" action="{U_ACTION}">
<form id="acp_portal_modules" method="post" action="{B3P_U_ACTION}">
<fieldset>
<dl>
<dt><label for="module_classname">{L_CHOOSE_MODULE}:</label><br /><span>{L_CHOOSE_MODULE_EXP}</span></dt>
@@ -48,18 +49,20 @@
<fieldset class="tabulated">
<legend>{L_ACP_PORTAL_MODULES}</legend>
<table cellspacing="1">
<table class="portal-modules-overview">
<tr>
<th style="text-align: center;" colspan="3">{L_MODULE_POS_TOP}</th>
<th style="text-align: center;">{L_MODULE_POS_TOP}</th>
</tr>
<!-- BEGIN modules_top -->
<!-- IF not modules_top.MODULE_ENABLED --><tr class="row3"><!-- ELSEIF modules_top.S_ROW_COUNT is even --><tr class="row1"><!-- ELSE --><tr class="row2"><!-- ENDIF -->
<td colspan="3">
<td>
{modules_top.MODULE_IMAGE} {modules_top.MODULE_NAME}<br />
<br />
<!-- IF modules_top.S_FIRST_ROW -->{ICON_MOVE_UP_DISABLED}<!-- ELSE --><a href="{modules_top.U_MOVE_UP}">{ICON_MOVE_UP}</a><!-- ENDIF -->&nbsp;
<!-- IF modules_top.S_LAST_ROW -->{ICON_MOVE_DOWN_DISABLED}<!-- ELSE --><a href="{modules_top.U_MOVE_DOWN}">{ICON_MOVE_DOWN}</a><!-- ENDIF -->&nbsp;
<a href="{modules_top.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_top.U_DELETE}">{ICON_DELETE}</a>
<span<!-- IF not modules_top.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_UP_DISABLED}&nbsp;</span>
<span<!-- IF modules_top.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_top.U_MOVE_UP}" data-ajax="b3p_move_module_up">{ICON_MOVE_UP}</a>&nbsp;</span>
<span<!-- IF not modules_top.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_DOWN_DISABLED}&nbsp;</span>
<span<!-- IF modules_top.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_top.U_MOVE_DOWN}" data-ajax="b3p_move_module_down">{ICON_MOVE_DOWN}</a>&nbsp;</span>
<a href="{modules_top.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_top.U_DELETE}" data-ajax="b3p_delete_module">{ICON_DELETE}</a>
</td>
</tr>
<!-- BEGINELSE -->
@@ -75,7 +78,7 @@
<table style="background-color: transparent; border: none; padding: 0px; margin: 0px;">
<tr style="vertical-align: top;">
<td style="width: 20%; font-size: 100%; line-height: 100%; padding: 0px; margin: 0px;">
<table cellspacing="1">
<table class="portal-modules-overview">
<tr>
<th>{L_MODULE_POS_LEFT}</th>
</tr>
@@ -84,11 +87,13 @@
<td>
{modules_left.MODULE_IMAGE} {modules_left.MODULE_NAME}<br />
<br />
<!-- IF modules_left.S_FIRST_ROW -->{ICON_MOVE_UP_DISABLED}<!-- ELSE --><a href="{modules_left.U_MOVE_UP}">{ICON_MOVE_UP}</a><!-- ENDIF -->&nbsp;
<span<!-- IF not modules_left.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_UP_DISABLED}&nbsp;</span>
<span<!-- IF modules_left.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_left.U_MOVE_UP}" data-ajax="b3p_move_module_up">{ICON_MOVE_UP}</a>&nbsp;</span>
<!-- IF modules_left.U_MOVE_RIGHT --><a href="{modules_left.U_MOVE_RIGHT}"><!-- IF S_CONTENT_DIRECTION eq 'rtl' -->{ICON_MOVE_LEFT}<!-- ELSE -->{ICON_MOVE_RIGHT}<!-- ENDIF --></a><!-- ELSE --><!-- IF S_CONTENT_DIRECTION eq 'rtl' -->{ICON_MOVE_LEFT_DISABLED}<!-- ELSE -->{ICON_MOVE_RIGHT_DISABLED}<!-- ENDIF --><!-- ENDIF -->&nbsp;
<a href="{modules_left.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_left.U_DELETE}">{ICON_DELETE}</a><br />
<a href="{modules_left.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_left.U_DELETE}" data-ajax="b3p_delete_module">{ICON_DELETE}</a><br />
<!-- IF S_CONTENT_DIRECTION eq 'rtl' -->{ICON_MOVE_RIGHT_DISABLED}<!-- ELSE -->{ICON_MOVE_LEFT_DISABLED}<!-- ENDIF -->&nbsp;
<!-- IF modules_left.S_LAST_ROW -->{ICON_MOVE_DOWN_DISABLED}<!-- ELSE --><a href="{modules_left.U_MOVE_DOWN}">{ICON_MOVE_DOWN}</a><!-- ENDIF -->
<span<!-- IF not modules_left.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_DOWN_DISABLED}&nbsp;</span>
<span<!-- IF modules_left.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_left.U_MOVE_DOWN}" data-ajax="b3p_move_module_down">{ICON_MOVE_DOWN}</a></span>
</td>
</tr>
<!-- BEGINELSE -->
@@ -102,7 +107,7 @@
</p>
</td>
<td style="font-size: 100%; line-height: 100%; padding: 0 12px;">
<table cellspacing="1">
<table class="portal-modules-overview">
<tr>
<th style="text-align: center;">{L_MODULE_POS_CENTER}</th>
</tr>
@@ -111,11 +116,13 @@
<td>
{modules_center.MODULE_IMAGE} {modules_center.MODULE_NAME}<br />
<br />
<!-- IF modules_center.S_FIRST_ROW -->{ICON_MOVE_UP_DISABLED}<!-- ELSE --><a href="{modules_center.U_MOVE_UP}">{ICON_MOVE_UP}</a><!-- ENDIF -->&nbsp;
<span<!-- IF not modules_center.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_UP_DISABLED}&nbsp;</span>
<span<!-- IF modules_center.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_center.U_MOVE_UP}" data-ajax="b3p_move_module_up">{ICON_MOVE_UP}</a>&nbsp;</span>
<!-- IF modules_center.U_MOVE_RIGHT --><a href="{modules_center.U_MOVE_RIGHT}">{ICON_MOVE_RIGHT}</a><!-- ELSE -->{ICON_MOVE_RIGHT_DISABLED}<!-- ENDIF -->&nbsp;
<a href="{modules_center.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_center.U_DELETE}">{ICON_DELETE}</a><br />
<a href="{modules_center.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_center.U_DELETE}" data-ajax="b3p_delete_module">{ICON_DELETE}</a><br />
<!-- IF modules_center.U_MOVE_LEFT --><a href="{modules_center.U_MOVE_LEFT}">{ICON_MOVE_LEFT}</a><!-- ELSE -->{ICON_MOVE_LEFT_DISABLED}<!-- ENDIF -->&nbsp;
<!-- IF modules_center.S_LAST_ROW -->{ICON_MOVE_DOWN_DISABLED}<!-- ELSE --><a href="{modules_center.U_MOVE_DOWN}">{ICON_MOVE_DOWN}</a><!-- ENDIF -->
<span<!-- IF not modules_center.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_DOWN_DISABLED}&nbsp;</span>
<span<!-- IF modules_center.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_center.U_MOVE_DOWN}" data-ajax="b3p_move_module_down">{ICON_MOVE_DOWN}</a></span>
</td>
</tr>
<!-- BEGINELSE -->
@@ -129,7 +136,7 @@
</p>
</td>
<td style="width: 20%; font-size: 100%; line-height: 100%; padding: 0px;">
<table cellspacing="1">
<table class="portal-modules-overview">
<tr>
<th>{L_MODULE_POS_RIGHT}</th>
</tr>
@@ -138,11 +145,13 @@
<td>
{modules_right.MODULE_IMAGE} {modules_right.MODULE_NAME}<br />
<br />
<!-- IF modules_right.S_FIRST_ROW -->{ICON_MOVE_UP_DISABLED}<!-- ELSE --><a href="{modules_right.U_MOVE_UP}">{ICON_MOVE_UP}</a><!-- ENDIF -->&nbsp;
<span<!-- IF not modules_right.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_UP_DISABLED}&nbsp;</span>
<span<!-- IF modules_right.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_right.U_MOVE_UP}" data-ajax="b3p_move_module_up">{ICON_MOVE_UP}</a>&nbsp;</span>
<!-- IF S_CONTENT_DIRECTION eq 'rtl' -->{ICON_MOVE_LEFT_DISABLED}<!-- ELSE -->{ICON_MOVE_RIGHT_DISABLED}<!-- ENDIF -->&nbsp;
<a href="{modules_right.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_right.U_DELETE}">{ICON_DELETE}</a><br />
<a href="{modules_right.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_right.U_DELETE}" data-ajax="b3p_delete_module">{ICON_DELETE}</a><br />
<!-- IF modules_right.U_MOVE_LEFT --><a href="{modules_right.U_MOVE_LEFT}"><!-- IF S_CONTENT_DIRECTION eq 'rtl' -->{ICON_MOVE_RIGHT}<!-- ELSE -->{ICON_MOVE_LEFT}<!-- ENDIF --></a><!-- ELSE --><!-- IF S_CONTENT_DIRECTION eq 'rtl' -->{ICON_MOVE_RIGHT_DISABLED}<!-- ELSE -->{ICON_MOVE_LEFT_DISABLED}<!-- ENDIF --><!-- ENDIF -->&nbsp;
<!-- IF modules_right.S_LAST_ROW -->{ICON_MOVE_DOWN_DISABLED}<!-- ELSE --><a href="{modules_right.U_MOVE_DOWN}">{ICON_MOVE_DOWN}</a><!-- ENDIF -->
<span<!-- IF not modules_right.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_DOWN_DISABLED}&nbsp;</span>
<span<!-- IF modules_right.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_right.U_MOVE_DOWN}" data-ajax="b3p_move_module_down">{ICON_MOVE_DOWN}</a></span>
</td>
</tr>
<!-- BEGINELSE -->
@@ -159,18 +168,20 @@
</table>
<br />
<table cellspacing="1">
<table class="portal-modules-overview">
<tr>
<th style="text-align: center;" colspan="3">{L_MODULE_POS_BOTTOM}</th>
<th style="text-align: center;">{L_MODULE_POS_BOTTOM}</th>
</tr>
<!-- BEGIN modules_bottom -->
<!-- IF not modules_bottom.MODULE_ENABLED --><tr class="row3"><!-- ELSEIF modules_bottom.S_ROW_COUNT is even --><tr class="row1"><!-- ELSE --><tr class="row2"><!-- ENDIF -->
<td colspan="3">
<td>
{modules_bottom.MODULE_IMAGE} {modules_bottom.MODULE_NAME}<br />
<br />
<!-- IF modules_bottom.S_FIRST_ROW -->{ICON_MOVE_UP_DISABLED}<!-- ELSE --><a href="{modules_bottom.U_MOVE_UP}">{ICON_MOVE_UP}</a><!-- ENDIF -->&nbsp;
<!-- IF modules_bottom.S_LAST_ROW -->{ICON_MOVE_DOWN_DISABLED}<!-- ELSE --><a href="{modules_bottom.U_MOVE_DOWN}">{ICON_MOVE_DOWN}</a><!-- ENDIF -->&nbsp;
<a href="{modules_bottom.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_bottom.U_DELETE}">{ICON_DELETE}</a>
<span<!-- IF not modules_bottom.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_UP_DISABLED}&nbsp;</span>
<span<!-- IF modules_bottom.S_FIRST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_bottom.U_MOVE_UP}" data-ajax="b3p_move_module_up">{ICON_MOVE_UP}</a>&nbsp;</span>
<span<!-- IF not modules_bottom.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->>{ICON_MOVE_DOWN_DISABLED}&nbsp;</span>
<span<!-- IF modules_bottom.S_LAST_ROW --> style="display: none;"<!-- ENDIF -->><a href="{modules_bottom.U_MOVE_DOWN}" data-ajax="b3p_move_module_down">{ICON_MOVE_DOWN}</a>&nbsp;</span>
<a href="{modules_bottom.U_EDIT}">{ICON_EDIT}</a> <a href="{modules_bottom.U_DELETE}" data-ajax="b3p_delete_module">{ICON_DELETE}</a>
</td>
</tr>
<!-- BEGINELSE -->
@@ -189,5 +200,7 @@
<!-- ENDIF -->
<!-- INCLUDEJS portal/ajax.js -->
<!-- INCLUDE overall_footer.html -->
<!-- ENDIF -->

View File

@@ -1,6 +1,6 @@
<!-- INCLUDE overall_header.html -->
<!-- INCLUDEJS portal/acp_portal.js -->
<!-- INCLUDEJS portal/acp_editor.js -->
<script type="text/javascript">
// <![CDATA[
/**
@@ -55,7 +55,7 @@ var help_line = {
function change_palette()
{
dE('colour_palette');
phpbb.toggleDisplay('colour_palette');
e = document.getElementById('colour_palette');
if (e.style.display == 'block')
@@ -83,7 +83,7 @@ function change_palette()
<p>{ERROR_MSG}</p>
</div>
<!-- ENDIF -->
<form id="acp_portal_config" method="post" action="{U_ACTION}">
<form id="acp_portal_config" method="post" action="{B3P_U_ACTION}">
<!-- IF SHOW_MODULE_OPTIONS -->
<fieldset>
<legend>{L_MODULE_OPTIONS}</legend>
@@ -145,7 +145,7 @@ function change_palette()
<!-- ENDIF -->
<fieldset>
<legend>{L_PORTAL_WELCOME}</legend>
<dl>
<dl><dt style="display: none;"></dt>
<dd>
<div id="colour_palette" style="display: none;">
<dl style="clear: left;">

99
adm/style/portal/ajax.js Normal file
View File

@@ -0,0 +1,99 @@
(function($) { // Avoid conflicts with other libraries
"use strict";
/**
* The following callbacks are for reording items. row_down
* is triggered when an item is moved down, and row_up is triggered when
* an item is moved up. It moves the row up or down, and deactivates /
* activates any up / down icons that require it (the ones at the top or bottom).
*/
phpbb.addAjaxCallback('b3p_move_module_up', function(res) {
if (typeof res.success === 'undefined' || !res.success) {
return;
}
var el = $(this).parents('tr:first'),
trSwap = el.prev(),
elClass = trSwap.attr('class'),
trSwapClass = el.attr('class');
el.insertBefore(trSwap);
el.attr('class', elClass);
trSwap.attr('class', trSwapClass);
// Swap images if swap element is first row
var swapIsFirstRow = trSwap.find('img[src*="icon_up_disabled"]').parents('span:first').is(':visible');
if (swapIsFirstRow) {
trSwap.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
}
// Swap images if move element is last row
var elIsLastRow = el.find('img[src*="icon_down_disabled"]').parents('span:first').is(':visible');
if (elIsLastRow) {
trSwap.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
}
});
phpbb.addAjaxCallback('b3p_move_module_down', function(res) {
if (typeof res.success === 'undefined' || !res.success) {
return;
}
var el = $(this).parents('tr:first'),
trSwap = el.next(),
elClass = trSwap.attr('class'),
trSwapClass = el.attr('class');
el.insertAfter(trSwap);
el.attr('class', elClass);
trSwap.attr('class', trSwapClass);
// Swap images if swap element is last row
var swapIsLastRow = trSwap.find('img[src*="icon_down_disabled"]').parents('span:first').is(':visible');
if (swapIsLastRow) {
trSwap.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down."]').parents('span:first').toggle();
el.find('img[src*="icon_down_disabled"]').parents('span:first').toggle();
}
// Swap images if move element is first row
var elIsFirstRow = el.find('img[src*="icon_up_disabled"]').parents('span:first').is(':visible');
if (elIsFirstRow) {
trSwap.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
trSwap.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up."]').parents('span:first').toggle();
el.find('img[src*="icon_up_disabled"]').parents('span:first').toggle();
}
});
phpbb.addAjaxCallback('b3p_delete_module', function(res) {
if (typeof res.success === 'undefined' || !res.success) {
return;
}
var el = $(this).parents('tr:first'),
nextEl = el.next();
el.remove();
// Fix classes of next elements
while (nextEl !== undefined && nextEl.is('tr')) {
var nextElClass = (nextEl.attr('class') === 'row1') ? 'row2' : 'row1';
nextEl.attr('class', nextElClass);
nextEl = nextEl.next();
}
});
})(jQuery); // Avoid conflicts with other libraries

View File

@@ -0,0 +1,10 @@
/* Board3 Portal 2.1 Admin Style Sheet
------------------------------------------------------------------------
Copyright 2014 board3 Group ( http://www.board3.de/ )
------------------------------------------------------------------------
*/
.portal-modules-overview {
border-collapse: separate;
border-spacing: 1px;
}

342
git-tools/hooks/commit-msg Executable file
View File

@@ -0,0 +1,342 @@
#!/bin/sh
#
# A hook to check for correct syntax similar to phpBB3 commit messages per:
# * <http://wiki.phpbb.com/display/DEV/Git>
# * <http://area51.phpbb.com/phpBB/viewtopic.php?p=209919#p209919>
#
# This is a commit-msg hook.
#
# To install this you can either copy or symlink it to
# $GIT_DIR/hooks
config_ns="b3p.hooks.commit-msg";
if [ "$(git config --bool $config_ns.fatal)" = "true" ]
then
fatal=1;
severity=Error;
else
fatal=0;
severity=Warning;
fi
debug_level=$(git config --int $config_ns.debug || echo 0);
# Error codes
ERR_LENGTH=1;
ERR_HEADER=2;
ERR_EMPTY=3;
ERR_DESCRIPTION=4;
ERR_FOOTER=5;
ERR_EOF=6;
ERR_UNKNOWN=42;
debug()
{
local level;
level=$1;
shift;
if [ $debug_level -ge $level ]
then
echo $@;
fi
}
quit()
{
if [ $1 -eq 0 ] || [ $1 -eq $ERR_UNKNOWN ]
then
# success
exit 0;
elif [ $fatal -eq 0 ]
then
# problems found but fatal is false
complain 'Please run `git commit --amend` and fix the problems mentioned.' 1>&2
exit 0;
else
complain "Aborting commit." 1>&2
exit $1;
fi
}
use_color()
{
if [ -z "$use_color_cached" ]
then
case $(git config --bool $config_ns.color)
in
false)
use_color_cached=1
;;
true)
use_color_cached=0
;;
*)
# tty detection in shell:
# http://hwi.ath.cx/jsh/list/shext/isatty.sh.html
tty 0>/dev/stdout >/dev/null 2>&1
use_color_cached=$?
;;
esac
fi
# return value is the flag inverted -
# if return value is 0, this means use color
return $use_color_cached
}
complain()
{
if use_color
then
# Careful: our argument may include arguments to echo like -n
# ANSI color codes:
# http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html
printf "\033[31m\033[1m"
if [ "$1" = "-n" ]
then
echo "$@"
printf "\033[0m"
else
# This will print one trailing space.
# Not sure how to avoid this at the moment.
echo "$@" $(printf "\033[0m")
fi
else
echo "$@"
fi
}
# Check for empty commit message
if ! grep -qv '^#' "$1"
then
# Commit message is empty (or contains only comments).
# Let git handle this.
# It will abort with a message like so:
#
# Aborting commit due to empty commit message.
exit 0
fi
msg=$(grep -v '^#' "$1" |grep -nE '.{81,}')
if [ $? -eq 0 ]
then
complain "The following lines are greater than 80 characters long:" >&2;
complain >&2
complain "$msg" >&2;
quit $ERR_LENGTH;
fi
lines=$(wc -l "$1" | awk '{ print $1; }');
expecting=header;
in_description=0;
in_empty=0;
ticket=0;
branch_regex="[a-z]+[a-z0-9-]*[a-z0-9]+";
i=1;
tickets="";
while [ $i -le $lines ]
do
# Grab the line we are studying
line=$(head -n$i "$1" | tail -n1);
debug 1 "==> [$i] $line (description: $in_description, empty: $in_empty)";
err=$ERR_UNKNOWN;
if [ -z "$expecting" ]
then
quit $err;
fi
if [ "${expecting#comment}" = "$expecting" ]
then
# Prefix comments to the expected tokens list
expecting="comment $expecting";
fi
debug 2 "Expecting: $expecting";
# Loop over each of the expected line formats
for expect in $expecting
do
# Reset the error code each iteration
err=$ERR_UNKNOWN;
# Test for validity of each line format
# This is done first so $? contains the result
case $expect in
"header")
err=$ERR_HEADER;
echo "$line" | grep -Eq "^\[(ticket/[0-9]+|feature/$branch_regex|task/$branch_regex)\] .+$"
result=$?
if ! echo "$line" | grep -Eq "^\[(ticket/[0-9]+|feature/$branch_regex|task/$branch_regex)\] [A-Z].+$"
then
# Don't be too strict.
# Commits may be temporary, intended to be squashed later.
# Just issue a warning here.
complain "$severity: heading should be a sentence beginning with a capital letter." 1>&2
complain "You entered:" 1>&2
complain "$line" 1>&2
fi
# restore exit code
(exit $result)
;;
"empty")
err=$ERR_EMPTY;
echo "$line" | grep -Eq "^$"
;;
"description")
err=$ERR_DESCRIPTION;
# Free flow text, the line length was constrained by the initial check
echo "$line" | grep -Eq "^.+$";
;;
"footer")
err=$ERR_FOOTER;
# Each ticket is on its own line
echo "$line" | grep -Eq "^B3P-[0-9]+$";
;;
"eof")
err=$ERR_EOF;
# Should not end up here
false
;;
"possibly-eof")
# Allow empty and/or comment lines at the end
! tail -n +"$i" "$1" |grep -qvE '^($|#)'
;;
"comment")
echo "$line" | grep -Eq "^#";
;;
*)
complain "Unrecognised token $expect" >&2;
quit $err;
;;
esac
# Preserve the result of the line check
result=$?;
debug 2 "$expect - '$line' - $result";
if [ $result -eq 0 ]
then
# Break out the loop on success
# otherwise roll on round and keep looking for a match
break;
fi
done
if [ $result -eq 0 ]
then
# Have we switched out of description mode?
if [ $in_description -eq 1 ] && [ "$expect" != "description" ] && [ "$expect" != "empty" ] && [ "$expect" != "comment" ]
then
# Yes, okay we need to backtrace one line and reanalyse
in_description=0;
i=$(( $i - $in_empty ));
# Reset the empty counter
in_empty=0;
continue;
fi
# Successful match, but on which line format
case $expect in
"header")
expecting="empty";
echo "$line" | grep -Eq "^\[ticket/[0-9]+\]$" && (
ticket=$(echo "$line" | sed 's,\[ticket/\([0-9]*\)\].*,\1,');
)
;;
"empty")
# Description might have empty lines as spacing
expecting="footer description";
in_empty=$(($in_empty + 1));
if [ $in_description -eq 1 ]
then
expecting="$expecting empty";
fi
;;
"description")
expecting="description empty";
in_description=1;
;;
"footer")
expecting="footer possibly-eof";
if [ "$tickets" = "" ]
then
tickets="$line";
else
tickets="$tickets $line";
fi
;;
"comment")
# Comments should expect the same thing again
;;
"possibly-eof")
expecting="eof";
;;
*)
complain "Unrecognised token $expect" >&2;
quit 254;
;;
esac
if [ "$expect" != "empty" ]
then
in_empty=0;
fi
debug 3 "Now expecting: $expecting";
else
# None of the expected line formats matched
# Guess we'll call it a day here then
complain "Syntax error on line $i:" >&2;
complain ">> $line" >&2;
complain -n "Expecting: " >&2;
complain "$expecting" | sed 's/ /, /g' >&2;
quit $err;
fi
i=$(( $i + 1 ));
done
# If EOF is expected exit cleanly
echo "$expecting" | grep -q "eof" || (
# Unexpected EOF, error
complain "Unexpected EOF encountered" >&2;
quit $ERR_EOF;
) && (
# Do post scan checks
if [ ! -z "$tickets" ]
then
# Check for duplicate tickets
dupes=$(echo "$tickets" | sed 's/ /\n/g' | sort | uniq -d);
if [ ! -z "$dupes" ]
then
complain "The following tickets are repeated:" >&2;
complain "$dupes" | sed 's/ /\n/g;s/^/* /g' >&2;
quit $ERR_FOOTER;
fi
fi
# Check the branch ticket is mentioned, doesn't make sense otherwise
if [ $ticket -gt 0 ]
then
echo "$tickets" | grep -Eq "\bB3P-$ticket\b" || (
complain "Ticket ID [$ticket] of branch missing from list of tickets:" >&2;
complain "$tickets" | sed 's/ /\n/g;s/^/* /g' >&2;
quit $ERR_FOOTER;
) || exit $?;
fi
# Got here okay exit to reality
exit 0;
);
exit $?;

88
git-tools/hooks/pre-commit Executable file
View File

@@ -0,0 +1,88 @@
#!/bin/sh
#
# A hook to disallow php syntax errors to be committed
# by running php -l (lint) on them. It requires php-cli
# to be installed.
#
# This is a pre-commit hook.
#
# To install this you can either copy or symlink it to
# $GIT_DIR/hooks, example:
#
# ln -s ../../git-tools/hooks/pre-commit \\
# .git/hooks/pre-commit
if [ -z "$PHP_BIN" ]
then
PHP_BIN=php
fi
if [ "$(echo -e test)" = test ]
then
echo_e="echo -e"
else
echo_e="echo"
fi
# necessary check for initial commit
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
errors=""
if ! which "$PHP_BIN" >/dev/null 2>&1
then
echo "PHP Syntax check failed:"
echo "PHP binary does not exist or is not in path: $PHP_BIN"
exit 1
fi
# dash does not support $'\n':
# http://forum.soft32.com/linux2/Bug-409179-DASH-Settings-IFS-work-properly-ftopict70039.html
IFS='
'
# get a list of staged files
for line in $(git diff-index --cached --full-index $against)
do
# split needed values
sha=$(echo $line | cut -d' ' -f4)
temp=$(echo $line | cut -d' ' -f5)
status=$(echo $temp | cut -d' ' -f1)
filename=$(echo $temp | cut -d' ' -f2)
# file extension
ext=$(echo $filename | sed 's/^.*\.//')
# only check files with php extension
if [ $ext != "php" ]
then
continue
fi
# do not check deleted files
if [ $status = "D" ]
then
continue
fi
# check the staged file content for syntax errors
# using php -l (lint)
result=$(git cat-file -p $sha | "$PHP_BIN" -n -l -ddisplay_errors\=1 -derror_reporting\=E_ALL -dlog_errrors\=0 2>&1)
if [ $? -ne 0 ]
then
# Swap back in correct filenames
errors=$(echo "$errors"; echo "$result" | grep ':' | sed -e "s@in - on@in $filename on@g")
fi
done
unset IFS
if [ -n "$errors" ]
then
echo "PHP Syntax check failed: "
$echo_e "$errors"
exit 1
fi

View File

@@ -0,0 +1,42 @@
#!/bin/sh
#
# A hook to add [$branch] to the beginning of a commit message
# if certain conditions are met.
#
# This is a prepare-commit-msg hook.
#
# To install this you can either copy or symlink it to
# $GIT_DIR/hooks, example:
#
# ln -s ../../git-tools/hooks/prepare-commit-msg \\
# .git/hooks/prepare-commit-msg
# get branch name
branch="$(git symbolic-ref HEAD)"
# exit if no branch name is present
# (eg. detached HEAD)
if [ $? -ne 0 ]
then
exit
fi
# strip off refs/heads/
branch="$(echo "$branch" | sed "s/refs\/heads\///g")"
# add [branchname] to commit message
# * only run when normal commit is made (without -m or -F;
# not a merge, etc.)
# * also make sure the branch name begins with bug/ or feature/
if [ "$2" = "" ]
then
tail="";
# Branch is prefixed with 'ticket/', append ticket ID to message
if [ "$branch" != "${branch##ticket/}" ];
then
tail="$(printf "\n\nB3P-${branch##ticket/}")";
fi
echo "[$branch] $tail$(cat "$1")" > "$1"
fi

View File

@@ -297,7 +297,7 @@ class main_menu extends module_base
$links = $this->utf_unserialize($portal_config['board3_menu_array_' . $module_id]);
$u_action = append_sid('index.' . $this->php_ext, 'i=\board3\portal\modules\portal&amp;mode=config&amp;module_id=' . $module_id);
$u_action = append_sid('index.' . $this->php_ext, 'i=%5Cboard3%5Cportal%5Cacp%5Cportal_module&amp;mode=config&amp;module_id=' . $module_id);
switch ($action)
{

View File

@@ -15,11 +15,13 @@ require_once(dirname(__FILE__) . '/../../acp/portal_module.php');
class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\database_test_case
{
static public $redirected = false;
static public $error = false;
static public $override_trigger_error = false;
public function setUp()
{
parent::setUp();
global $db, $cache, $phpbb_root_path, $phpEx, $user, $phpbb_container, $template;
global $db, $cache, $phpbb_root_path, $phpEx, $user, $phpbb_container, $request, $template;
$user = new \board3\portal\tests\mock\user();
$phpbb_container = new \phpbb_mock_container_builder();
// Mock version check
@@ -55,6 +57,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE',
'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW',
));
$request = new \phpbb_mock_request;
$this->portal_module = new \board3\portal\acp\portal_module();
$this->update_portal_modules();
}
@@ -283,3 +286,12 @@ function adm_back_link($url)
{
return $url;
}
function trigger_error($input, $type = E_USER_NOTICE)
{
if (!phpbb_acp_move_module_test::$override_trigger_error)
{
\trigger_error($input, $type);
}
phpbb_acp_move_module_test::$error = $input;
}

View File

@@ -34,6 +34,45 @@ class phpbb_functional_portal_acp_test extends \board3\portal\tests\testframewor
*/
public function test_acp_pages($mode)
{
$crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&amp;mode=' . $mode . '&sid=' . $this->sid);
$crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&mode=' . $mode . '&sid=' . $this->sid);
}
public function test_move_first_module_up()
{
$crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&mode=modules&sid=' . $this->sid);
$module_link = $crawler->filter('table')->eq(3)->filter('tr')->eq(1)->filter('a')->eq(0)->attr('href');
preg_match('/module_id=(?:([0-9]{1,3}))/', $module_link, $output);
$this->assertNotEmpty($output[1]);
$module_id = $output[1];
$crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&mode=modules&module_id=' . $module_id . '&action=move_up&sid=' . $this->sid);
}
public function test_move_last_module_down()
{
$crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&mode=modules&sid=' . $this->sid);
$module_link = $crawler->filter('table')->eq(3)->filter('tr')->last()->filter('a')->eq(0)->attr('href');
preg_match('/module_id=(?:([0-9]{1,3}))/', $module_link, $output);
$this->assertNotEmpty($output[1]);
$module_id = $output[1];
$crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&mode=modules&module_id=' . $module_id . '&action=move_down&sid=' . $this->sid);
}
public function test_delete_module()
{
$crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&mode=modules&sid=' . $this->sid);
$module_link = str_replace(array('./../', '%5C'), array('', '\\'), $crawler->filter('table')->eq(3)->filter('tr')->last()->filter('a')->eq(3)->attr('href'));
$crawler = self::request('GET', $module_link);
preg_match('/module_classname=(?:([a-z0-9\\\_]+))/', $module_link, $module_name);
$module_name = $module_name[1];
$this->assertContains('Are you sure you wish to delete the module', $crawler->text());
$form = $crawler->selectButton('confirm')->form();
$crawler = self::submit($form);
$this->assertContains('The module was removed successfully.', $crawler->text());
// Add it back
$crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&mode=modules&add[center]=true&sid=' . $this->sid);
$form = $crawler->selectButton('submit')->form();
$form->setValues(array('module_classname' => $module_name));
$crawler = self::submit($form);
}
}

View File

@@ -30,6 +30,15 @@ class user extends \PHPUnit_Framework_TestCase
return; // can't support other extensions
}
if (is_array($file))
{
foreach ($file as $cur_file)
{
$this->add_lang_ext($ext, $cur_file);
}
return;
}
if (file_exists(dirname(__FILE__) . '/../../language/en/' . $file . '.php'))
{
include_once(dirname(__FILE__) . '/../../language/en/' . $file . '.php');