From 46b12fbecd0b73f51a883a6d6d440b10553d2b0f Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 7 Aug 2016 11:37:19 +0200 Subject: [PATCH] Minor Fixes to the router --- admin/action.php | 2 +- admin/assets/js/page.bodyparser.js | 144 +++++ admin/install-dev.php | 2 +- admin/lang.php | 10 + admin/mail.php | 2 +- admin/new_user.php | 2 +- admin/permissions.php | 2 +- admin/roles.php | 8 +- admin/user_settings.php | 14 +- apps/Files/config.php | 2 +- apps/Files/index.php | 683 ++++++++++++----------- apps/SimplePages/backend/confirm.php | 2 +- apps/SimplePages/backend/edit.php | 2 +- apps/SimplePages/backend/permissions.php | 2 +- inc/autoload_adm.php | 2 +- inc/footer.php | 183 +++--- inc/libs/functions.php | 7 +- inc/libs/lang.class.php | 1 + 18 files changed, 637 insertions(+), 433 deletions(-) create mode 100644 admin/assets/js/page.bodyparser.js create mode 100644 admin/lang.php diff --git a/admin/action.php b/admin/action.php index 40f243d..768341f 100755 --- a/admin/action.php +++ b/admin/action.php @@ -55,7 +55,7 @@ if (hasPerm('manage_system')) ?>

get('action_construction_message_edit');?>

-
+
diff --git a/admin/assets/js/page.bodyparser.js b/admin/assets/js/page.bodyparser.js new file mode 100644 index 0000000..30a4d21 --- /dev/null +++ b/admin/assets/js/page.bodyparser.js @@ -0,0 +1,144 @@ +;(function() { + + // bind forms + function pageBodyParser() { + window.removeEventListener('click', bodyParser, false); + window.removeEventListener('keypress', bodyParser, false); + window.addEventListener('click', bodyParser, false); + window.addEventListener('keypress', bodyParser, false); + } + + // handle forms in a manner similar to body-parser + function bodyParser(e) { + var el = e.target, + form = el, + nodeName = el.nodeName, + keycode = (e.keyCode ? e.keyCode : e.which), + link, + proto, + path, + orig, + body = {}, + submitAdded, + i, + l, + control; + + if (e.type === 'keypress') { + if (keycode === 13) { + if (nodeName !== 'INPUT') { + return; // enter key only valid when a form is focused + } + } + else { + return; // ignore other keypresses + } + } + else { + if (nodeName !== 'INPUT' && nodeName !== 'BUTTON') { + return; // something other than a submit button was clicked + } + else if (nodeName === 'INPUT' && el.type !== 'submit') { + return; // input was clicked that is not a submit button + } + } + + // find parent form + while (form && 'FORM' !== form.nodeName) { + form = form.parentNode; + } + + // no parent form + if (!form) { + return; + } + + link = form.action; + + // strip protocol + proto = link.split('://'); + if (proto) { + if (proto[1]) { + link = proto[1]; + form.pathname = link = proto[1].replace(location.host, ''); + } + } + + // normalize hash / search + if (!form.hash) { + form.hash = ''; + } + if (!form.search) { + form.search = ''; + } + + // ensure non-hash for the same path + if (form.pathname === location.pathname && (form.hash || '#' === link)) return; + + // x-origin + if (!page.sameOrigin(form.action)) return; + + // rebuild path + path = form.pathname + form.search + (form.hash || ''); + + // same page + orig = path + form.hash; + + function addToBody(el, val) { + if (el.name) { + body[el.name] = val; + } + else if (el.id) { + body[el.id] = val; + } + } + + // build req.body + l = form.elements.length; + addToBody(el, el.value); + if ((el.name || el.id) && el.type === 'submit') { + submitAdded = true; + } + for (i = 0; i < l; i++) { + control = form.elements[i]; + if (control.type === 'checkbox') { + addToBody(control, control.checked); + } + else if (control.type === 'submit') { + if (!submitAdded) { + addToBody(control, control.value); + submitAdded = true; + } + } + else if (control.nodeName !== 'BUTTON') { + if (control.type !== 'radio' || control.checked) { + addToBody(control, control.value); + } + } + } + + e.preventDefault(); + page.show(orig, {body: body}); + } + + var Context = page.Context; + + // overload page.js show method to add support for body parser + page.show = function(path, state, dispatch) { + var ctx = new Context(path, state); + page.current = ctx.path; + if (state && state.body) ctx.body = state.body; // new + if (false !== dispatch) page.dispatch(ctx); + if (false !== ctx.handled) ctx.pushState(); + return ctx; + }; + + // expose pageBodyParser + if ('undefined' == typeof module) { + window.pageBodyParser = pageBodyParser; + } + else { + module.exports = pageBodyParser; + } + +})(); \ No newline at end of file diff --git a/admin/install-dev.php b/admin/install-dev.php index ca64824..057037e 100644 --- a/admin/install-dev.php +++ b/admin/install-dev.php @@ -285,7 +285,7 @@ else ?>
-
+

Language

Select your language:

diff --git a/admin/new_user.php b/admin/new_user.php index 3931dd3..1f3f70a 100755 --- a/admin/new_user.php +++ b/admin/new_user.php @@ -48,7 +48,7 @@ if (hasPerm('manage_admins')) ?>
- +

get('admins_cn_username'); ?>:

get('admins_cn_password'); ?>: diff --git a/admin/permissions.php b/admin/permissions.php index b6d5d20..f37b62a 100755 --- a/admin/permissions.php +++ b/admin/permissions.php @@ -34,7 +34,7 @@ if (hasPerm('edit_permissions')) } } else { - echo '

'; + echo '
'; //Admin Groups $db->get(); $role_names = []; diff --git a/admin/roles.php b/admin/roles.php index 450c65b..f043663 100755 --- a/admin/roles.php +++ b/admin/roles.php @@ -39,7 +39,7 @@ if (hasPerm('manage_groups')) { ?>
- +

get('admins_roles_delete_confirm');?>

get('general_no');?> @@ -65,7 +65,7 @@ if (hasPerm('manage_groups')) { ?>
- +

get('admins_roles_user_delete_confirm');?>

get('general_no');?> @@ -129,7 +129,7 @@ if (hasPerm('manage_groups')) } else { ?> - + get('admins_roles_add_user');?>:
diff --git a/admin/user_settings.php b/admin/user_settings.php index 35bda56..5c2f76b 100755 --- a/admin/user_settings.php +++ b/admin/user_settings.php @@ -41,7 +41,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid']) { ?>
-
+

' . $lang->get('user_settings_new_pass') . '

'; ?> - +
- +
@@ -121,7 +121,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid']) echo ''; ?> -

get('user_settings_2fa_deactivate_confirm'); ?>

-

+ get('general_no'); ?>
@@ -197,7 +197,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid']) echo '

'; ?>

get('user_settings_2fa_confirm_code'); ?>:

-
+

@@ -231,7 +231,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid']) { ?>

- +

get('username'); ?>:

diff --git a/apps/Files/config.php b/apps/Files/config.php index 3bde177..08610a9 100755 --- a/apps/Files/config.php +++ b/apps/Files/config.php @@ -5,5 +5,5 @@ $GLOBALS['lang']->set('Manage Files', 'files_title', 'en'); $_CONF['mod_name'] = 'Files'; $_CONF['mod_desc'] = 'Ein Modul zum Anzeigen & Uploaden von Dateien'; $_CONF['menu_top'] = ' '.$GLOBALS['lang']->get('files_title'); -$_CONF['menu'] = ['menu_top' => 'index.php']; +$_CONF['menu'] = ['menu_top' => 'index.php" rel="external']; $_CONF['type'] = 'none'; diff --git a/apps/Files/index.php b/apps/Files/index.php index 38c52e1..523e9f5 100755 --- a/apps/Files/index.php +++ b/apps/Files/index.php @@ -302,366 +302,391 @@ if (isset($_SESSION['user'])) - + '.print_r($data_old, true).''; - echo ''; + echo '
'; echo '
'; } else diff --git a/apps/SimplePages/backend/edit.php b/apps/SimplePages/backend/edit.php index ce2fed0..65d62a7 100755 --- a/apps/SimplePages/backend/edit.php +++ b/apps/SimplePages/backend/edit.php @@ -275,7 +275,7 @@ if (hasPerm('manage_pages')) ?> -
+

get('sp_edit_title');?>:

get('sp_edit_alias');?>:'; ?> - +