1
0
mirror of https://github.com/Mowie/Mowie synced 2024-06-03 09:29:38 +00:00

Minor Fixes to the router

This commit is contained in:
kolaente 2016-08-07 11:37:19 +02:00
parent 6ddb3c6629
commit 46b12fbecd
18 changed files with 637 additions and 433 deletions

View File

@ -55,7 +55,7 @@ if (hasPerm('manage_system'))
?>
<div class="main">
<h1><?php echo $lang->get('action_construction_message_edit');?></h1>
<form action="" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
<textarea id="editor" name="constr_message"><?php require('../inc/System/construction2.txt'); ?></textarea>
<input type="submit" value="<?php echo $lang->get('general_save_changes');?>"/>
</form>

View File

@ -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;
}
})();

View File

@ -285,7 +285,7 @@ else
?>
<div class="install-container">
<form action="" method="post" class="form">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post" class="form">
<h2>Language</h2>
<span>Select your language:</span>
<select name="lang">

10
admin/lang.php Normal file
View File

@ -0,0 +1,10 @@
<?php
session_name('adminsession');
session_start();
require_once '../inc/config.php';
if(isset($_GET['set']))
{
$_SESSION['lang'] = $_GET['set'];
echo '1';
}

View File

@ -32,7 +32,7 @@ if (isset($_GET['to']))
<div class="main">
<h1><?php printf($lang->get('mail_write_to'), $_GET['to']); ?></h1>
<div class="form">
<form action="" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
<p><span><?php echo $lang->get('admins_username'); ?>:</span>
<input type="text" value="<?php echo $_SESSION['user']; ?>" name="from"/>
</p>

View File

@ -48,7 +48,7 @@ if (hasPerm('manage_admins'))
?>
<div class="main">
<div class="form">
<form action="" method="POST">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="POST">
<p><span><?php echo $lang->get('admins_cn_username'); ?>:</span><input type="text" name="userN"/>
</p>
<p><span><?php echo $lang->get('admins_cn_password'); ?>:</span><input type="password" name="pw1"/>

View File

@ -34,7 +34,7 @@ if (hasPerm('edit_permissions'))
}
} else
{
echo '<div class="main"><form action="" method="post">';
echo '<div class="main"><form action="'.$_SERVER['REQUEST_URI'].'" method="post">';
//Admin Groups
$db->get();
$role_names = [];

View File

@ -39,7 +39,7 @@ if (hasPerm('manage_groups'))
{
?>
<div class="main" style="text-align: center">
<form action="" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
<p><?php echo $lang->get('admins_roles_delete_confirm');?></p>
<input type="submit" name="del" value="<?php echo $lang->get('general_yes');?>"/>
<a href="roles.php?members=<?php echo $_GET['members']; ?>" class="button btn_del"><?php echo $lang->get('general_no');?></a>
@ -65,7 +65,7 @@ if (hasPerm('manage_groups'))
{
?>
<div class="main" style="text-align: center">
<form action="" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
<p><?php echo $lang->get('admins_roles_user_delete_confirm');?></p>
<input type="submit" name="del" value="<?php echo $lang->get('general_yes');?>"/>
<a href="roles.php?members=<?php echo $_GET['members']; ?>" class="button btn_del"><?php echo $lang->get('general_no');?></a>
@ -129,7 +129,7 @@ if (hasPerm('manage_groups'))
} else
{
?>
<form action="" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
<?php echo $lang->get('admins_roles_add_user');?>:
<select name="user">
<?php
@ -168,7 +168,7 @@ if (hasPerm('manage_groups'))
?>
<div class="main">
<h2><?php echo $lang->get('admins_roles_create_group');?></h2>
<form action="" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
<input type="text" name="group_name" placeholder="<?php echo $lang->get('admins_roles_group_name');?>"/><br/>
<input type="submit" name="submit" value="<?php echo $lang->get('admins_roles_create_group');?>"/>
</form>

View File

@ -41,7 +41,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid'])
{
?>
<div class="main">
<form action="?pw_new" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
<input type="password" name="pw_new"
placeholder="<?php echo $lang->get('user_settings_new_pass'); ?>" autofocus/><br/>
<input type="password" name="pw_new2"
@ -67,7 +67,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid'])
{
echo '<div class="main"><p>' . $lang->get('user_settings_new_pass') . '</p>';
?>
<form action="?pw_new" method="post">
<form action="<?php echo parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);?>?pw_new" method="post">
<input type="password" name="pw_new"
placeholder="<?php echo $lang->get('user_settings_new_pass'); ?>" autofocus/><br/>
<input type="password" name="pw_new2"
@ -85,7 +85,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid'])
{
?>
<div class="main">
<form action="" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
<input type="password" name="pw" autofocus
placeholder="<?php echo $lang->get('user_settings_enter_current_pass'); ?>"/><br/>
<input type="submit" value="<?php echo $lang->get('confirm'); ?>"/>
@ -121,7 +121,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid'])
echo '</table>';
?>
<form action="" method="post"><input type="submit" name="smbt"
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post"><input type="submit" name="smbt"
value="<?php echo $lang->get('user_settings_current_sessions_logout_all'); ?>"/>
</form></div>
<?php
@ -157,7 +157,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid'])
?>
<p><?php echo $lang->get('user_settings_2fa_deactivate_confirm'); ?></p>
<p>
<form action="" method="post" style="text-align: center;">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post" style="text-align: center;">
<input type="submit" name="confirm" value="<?php echo $lang->get('general_yes'); ?>"/>
<a onclick="history.back();" class="button btn_del"><?php echo $lang->get('general_no'); ?></a>
</form>
@ -197,7 +197,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid'])
echo '<img src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&format=svg&data=' . $qrCodeUrl . '" alt=""/></p>';
?>
<p><?php echo $lang->get('user_settings_2fa_confirm_code'); ?>:</p>
<form action="" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post">
<p><input type="text" placeholder="<?php echo $lang->get('user_settings_2fa_enter_code'); ?>"
name="2fatest" autocomplete="off"/>
<input type="hidden" name="secret" value="<?php echo $secret; ?>"/>
@ -231,7 +231,7 @@ if (hasPerm('manage_admins') || $uid == $_SESSION['userid'])
{
?>
<div class="main">
<form action="" class="form" method="post">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" class="form" method="post">
<p><span><?php echo $lang->get('username'); ?>:</span><input name="username"
value="<?php echo $db->data[0]['username'] ?>"/>
</p>

View File

@ -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'] = '<i class="icon-folder2"></i> '.$GLOBALS['lang']->get('files_title');
$_CONF['menu'] = ['menu_top' => 'index.php'];
$_CONF['menu'] = ['menu_top' => 'index.php" rel="external'];
$_CONF['type'] = 'none';

View File

@ -302,16 +302,38 @@ if (isset($_SESSION['user']))
<script>
var webUri = '<?php echo $MCONF['web_uri'];?>';
</script>
<script src="<?php echo $MCONF['web_uri']; ?>apps/Files/js/jquery.history.js"></script>
<!--<script src="<?php echo $MCONF['web_uri']; ?>apps/Files/js/jquery.history.js"></script>-->
<script src="<?php echo $MCONF['web_uri']; ?>apps/Files/js/jquery.tablesorter.min.js"></script>
<script src="<?php echo $MCONF['web_uri']; ?>apps/Files/js/jquery.tablesorter.staticrow.js"></script>
<!--<script src="<?php echo $MCONF['web_uri']; ?>apps/Files/js/files.js"></script>-->
<script>
page('apps/Files/:var', function (ctx, next) {
console.log(ctx);
/*if(!ctx.init) {
next();
//window.location.replace('<?php echo $MCONF['home_uri']; ?>apps/Files/index.php#folder=');
//location.reload();
}*/
//else {*/
if (!window.location.hash) {
var url = '';
} else {
var url = window.location.hash.replace('#folder=', '').replace(folder_curr, '');
}
var folder_curr = $('#displayUrl').html();
getFiles(url);
window.onbeforeunload = function() { return "Your work will be lost."; };
//}
});
//getFiles('');
function getFiles(folder) {
var filesContent = '';
console.log(folder);
//console.log(folder);
$.ajax({
url: webUri + 'apps/Files/index.php?json&folder=' + folder,
url: webUri + 'apps/Files/index.php?ajax&json&folder=' + folder,
dataType: 'json',
success: function (data) {
msgDo('&nbsp;');
@ -323,11 +345,14 @@ if (isset($_SESSION['user']))
$('#delFolder').show();
//History
var title = $(document).find("title").text();
historyc(webUri + 'apps/Files/index.php?folder_view=' + data.displayUrl, title);
//historyc(webUri + 'apps/Files/index.php#folder_view=' + data.displayUrl, title);
}
$('#files').html('<h3 id="displayUrl">' + data.displayUrl + '</h3><table id="filesList" width="100%"><thead><tr><th><?php echo $lang->get('files_filename'); ?></th><th><?php echo $lang->get('files_last_modified'); ?></th><th><?php echo $lang->get('files_filetype'); ?></th><th><?php echo $lang->get('files_filesize'); ?></th></tr></thead><tbody id="filesContent"></tbody></table><div id="extra"></div>');
$.each(data.files, function () {
if(this.type == 'Ordner') {
var name = '<a href="#folder=' + data.displayUrl + this.name + '"><i class="icon-' + this.icon + '"></i> ' + this.name;
} else// onclick="openFile(\'' + this.name + '\', \'' + this.icon + '\', \'' + webUri + data.displayUrl + this.name + '\');"
if (this.name == '..') {
var name = '<a onclick="openFile(\'..\', \'' + this.icon + '\', \'' + webUri + data.displayUrl + this.name + '\');"><i class="icon-' + this.icon + '"></i> ' + this.name;
} else {
@ -362,10 +387,10 @@ if (isset($_SESSION['user']))
}, 300);
}
getFiles('');
//getFiles('');
function openFile(file, type, url) {
console.log(file, type);
//console.log(file, type);
if (type == 'folder2') {
var folder_curr = $('#displayUrl').html();
getFiles(folder_curr + file);
@ -429,7 +454,7 @@ if (isset($_SESSION['user']))
//Neuen ordner
function newFolder() {
$('#extra').html('<div class="overlay" style="display:none;"><div class="window"><div class="head"><?php echo $lang->get('files_create_dir'); ?><a onclick="closeW();" class="closeMsg"><i class="icon-close"></i></a></div><div id="content"></div></div></div>');
$('#content').append('<p><form action="" onsubmit="newFolderSub();return false;"><input type="text" class="select" placeholder="<?php echo $lang->get('files_enter_name'); ?>" id="folderName" autofocus/><input type="submit" value="<?php echo $lang->get('files_create_dir'); ?>"/></form></p>');
$('#content').append('<p><form onsubmit="newFolderSub();return false;"><input type="text" class="select" placeholder="<?php echo $lang->get('files_enter_name'); ?>" id="folderName" autofocus/><input type="submit" value="<?php echo $lang->get('files_create_dir'); ?>"/></form></p>');
$('#folderName').focus();
//uuund einbelnden
$(".overlay").fadeIn(250);
@ -442,7 +467,7 @@ if (isset($_SESSION['user']))
$.ajax({
type: 'POST',
url: webUri + 'apps/Files/index.php?newFolder',
data: 'name=' + $('#folderName').val() + '&dir=' + folder,
data: 'ajax&name=' + $('#folderName').val() + '&dir=' + folder,
success: function (msg) {
console.log(msg);
if (msg == 'success') {
@ -630,7 +655,7 @@ if (isset($_SESSION['user']))
}
//history
function historyc(url, title) {
/*function historyc(url, title) {
//Histroy state
var State = History.getState(), $log = $('#log');
History.Adapter.bind(window, 'statechange', function () {
@ -658,10 +683,10 @@ if (isset($_SESSION['user']))
History.pushState({
state: 1,
rand: Math.random()
}, title, webUri + 'apps/Files/index.php?folder_view=' + curr);
}, title, webUri + 'apps/Files/index.php#folder_view=' + curr);
getFiles(curr + '..');
}
});
});*/
</script>
<!--<script src='<?php echo $MCONF['web_uri']; ?>js/video.js'></script>-->
<?php

View File

@ -93,7 +93,7 @@ if (isset($_GET['page']))
$data_display['lastedit'] = $data_new['lastedit'];
//echo '<pre>'.print_r($data_old, true).'</pre>';
echo '<form action="" method="post"><input type="hidden" name="contentToUpdate" value=\'' . json_encode($data_display) . '\'/><input type="submit" name="confirm" value="'.$lang->get('sp_confirm_confirm').'"/><input type="submit" name="delete" value="'.$lang->get('sp_confirm_delete').'" class="btn_del"/></form>';
echo '<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post"><input type="hidden" name="contentToUpdate" value=\'' . json_encode($data_display) . '\'/><input type="submit" name="confirm" value="'.$lang->get('sp_confirm_confirm').'"/><input type="submit" name="delete" value="'.$lang->get('sp_confirm_delete').'" class="btn_del"/></form>';
echo '</div>';
}
else

View File

@ -275,7 +275,7 @@ if (hasPerm('manage_pages'))
?>
<span id="response"></span>
<form id="edit" method="post" action="" class="form">
<form id="edit" method="post" action="<?php echo $_SERVER['REQUEST_URI']?>" class="form">
<p><span><?php echo $lang->get('sp_edit_title');?>:</span><input type="text" name="title" value="<?php echo $data[0]['title']; ?>"/>
</p>
<p><span><?php echo $lang->get('sp_edit_alias');?>:</span><input type="text" name="alias"

View File

@ -89,7 +89,7 @@ if (hasPerm('grant_permissions'))
echo '</td>';
?>
<td>
<form action="" method="post" style="padding:0;margin:0;">
<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post" style="padding:0;margin:0;">
<input type="hidden" name="page" value="<?php echo $data['id']; ?>"/>
<select name="user" style="margin:0;">
<?php

View File

@ -4,7 +4,7 @@ session_start();
require_once '../inc/config.php';
//Language
$lang = new lang();
//$lang = new lang();
$lang->setLangFolder('lang/');
require_once '../inc/libs/functions.php';

View File

@ -4,8 +4,10 @@ if(!isset($_GET['direct']))
?>
</div>
<div id="showMsg"></div>
<script src="<?php echo $MCONF['web_uri']?>admin/assets/js/page.js"></script>
<!--<script src="<?php echo $MCONF['web_uri'] ?>admin/assets/js/page.js"></script>
<script src="<?php echo $MCONF['web_uri'] ?>admin/assets/js/page.bodyparser.js"></script>-->
<script>
//Msg
function showMsg(msg) {
$('#showMsg').html('<div class="snackbar"><a onclick="closeMsg();" class="closeMsg"><i class="icon-close"></i> </a><p>' + msg + '</p></div>');
}
@ -25,48 +27,65 @@ if(!isset($_GET['direct']))
$('.toploading').animate({height: "0"}, 150);
}
$(document).ready(function() {
//Form
// pre-submit callback
function showLoader(formData, jqForm, options) {
//Change current Language
function changeLang(lang) {
showTopLoader();
console.log('Form');
return true;
$.get('<?php echo $MCONF['home_uri'];?>admin/lang.php?set=' + lang, function (data) {
console.log(data);
if(data == 1){
location.reload();
} else {
showMsg('Error.');
}
})
}
// post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
//return false;
hideTopLoader();
console.log(statusText);
}
//Error
function showError(e) {
console.log(e);
}
var options = {
target: '#loader',
beforeSubmit: showLoader,
success: showResponse,
error: showError,
resetForm: false,
data: {direct: ''}
};
$('form').ajaxForm(options);
$(document).ready(function () {
//Router
$('#topnav').addClass('no-transition');
page.base('<?php echo $MCONF['home_uri'];?>');
///page.base('<?php echo $MCONF['home_uri'];?>');
page('*', findPage);
page();
pageBodyParser();
function findPage(ctx, next) {
//console.log(ctx);
if(!ctx.init) {
//if('<?php echo str_replace($MCONF['home_uri'], '', $MCONF['web_uri']);?>' + ctx.canonicalPath != window.location.href) {
if (ctx.body) { //If POST-Request, send Post via ajax
var isAjax = false;
var requestData = 'direct=true';
for (var key in ctx.body) {
if (!ctx.body.hasOwnProperty(key)) continue;
requestData += '&' + key + '=' + ctx.body[key];
if(key == 'ajax') isAjax = true;
}
if(!isAjax) {
$.ajax({
url: ctx.canonicalPath,
type: 'POST',
cache: false,
data: requestData,
beforeSend: function () {
showTopLoader();
},
complete: function () {
hideTopLoader();
},
success: function (result) {
$("#loader").html(result);
},
error: function (xhr, status, error) {
console.log(status, error);
}
});
}
} else {//Otherwise display Contents
showTopLoader();
//Load Title
@ -122,7 +141,7 @@ if(!isset($_GET['direct']))
showMsg('Error.');
}
});
// }
}
}
}
});

View File

@ -229,7 +229,12 @@ function printHeader($title)
<link rel="stylesheet" href="' . $GLOBALS['MCONF']['web_uri'] . 'admin/assets/admin.css" type="text/css"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<script src="' . $GLOBALS['MCONF']['web_uri'] . 'admin/assets/js/jquery.min.js"></script>
<script src="' . $GLOBALS['MCONF']['web_uri'] . 'admin/assets/js/jquery.form.min.js"></script>
<script src="' . $GLOBALS['MCONF']['web_uri'] . 'admin/assets/js/page.js"></script>
<script src="' . $GLOBALS['MCONF']['web_uri'] . 'admin/assets/js/page.bodyparser.js"></script>
<script>
page.base(\'' . $GLOBALS['MCONF']['home_uri'] . '\');
</script>
</head>
<body>';
if (is_loggedin())

View File

@ -11,6 +11,7 @@ class lang
{
$this->default = $default;
$this->lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if(isset($_SESSION['lang'])) $this->lang = $_SESSION['lang'];
$this->langfiles = [];
}