Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/application/views/tools/dp_encoder_end.php
2018-10-16 18:28:42 +02:00

198 lines
6.6 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
if($type == 'url') { ?>
<script type="text/javascript">
$('#url-encode #submit').click(function() {
url_encoder(url_getSelected());
});
$('#url-encode .radio-inline').change(function() {
$('#url-encode #submit').text(url_getSelected());
if(url_getSelected() == '<?= lang('url_encode'); ?>') {
var input = '<?= lang('url_input2'); ?>';
var output = '<?= lang('url_output2'); ?>';
} else if (url_getSelected() == '<?= lang('url_decode'); ?>') {
var input = '<?= lang('url_input3'); ?>';
var output = '<?= lang('url_output3'); ?>';
}
$('#url-encode #input').attr('placeholder', input);
$('#url-encode #output').attr('placeholder', output);
});
var url_getSelected = function() {
var selectedMethod = "";
var selected = $("input[type='radio'][name=encodeDecode]:checked");
if(selected.length > 0) {
selectedMethod = selected.val();
}
return selectedMethod;
}
var url_encoder = function(selectedMethod) {
var text = $('#url-encode #input').val();
if(selectedMethod == '<?= lang('url_encode'); ?>') {
var output = encodeURIComponent(text);
} else {
var output = decodeURIComponent(text);
}
$('#url-encode #output').text(output);
}
</script>
<?php } elseif($type == 'base64') { ?>
<script type="text/javascript">
jQuery.base64 = (function($) {
var _PADCHAR = "=",
_ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
_VERSION = "1.0";
function _getbyte64(s, i) {
var idx = _ALPHA.indexOf(s.charAt(i));
if(idx === -1) {
throw "Cannot decode base64";
}
return idx;
}
function _decode(s) {
var pads = 0,
i,
b10,
imax = s.length,
x = [];
s = String(s);
if(imax % 4 !== 0) {
throw "Cannot decode base64";
}
if(s.charAt(imax - 1) === _PADCHAR) {
pads = 1;
if(s.charAt(imax-2) === _PADCHAR) {
pads = 2;
}
imax -= 4;
}
for(i = 0; i < imax; i += 4) {
b10 = (_getbyte64(s,i) << 18) | (_getbyte64(s,i+1) << 12) | (_getbyte64(s,i+2) << 6) | (_getbyte64(s,i + 3));
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff, b10 & 0xff));
}
switch (pads) {
case 1:
b10 = (_getbyte64(s,i) << 18) | (_getbyte64(s,i+1) << 12) | (_getbyte64(s,i+2) << 6);
x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff));
break;
case 2:
b10 = (_getbyte64(s,i) << 18) | (_getbyte64(s,i+1) << 12);
x.push(String.fromCharCode(b10 >> 16));
break;
}
return x.join("");
}
function _getbyte(s,i) {
var x = s.charCodeAt(i);
if(x > 255) {
throw "INVALID_CHARACTER_ERR: DOM Exeption 5";
}
return x;
}
function _encode(s) {
if(arguments.length !== 1) {
throw "SyntaxError: exactly one argument required";
}
s = String(s);
var i,
b10,
x = [],
imax = s.length - s.length % 3;
if(s.length === 0) {
return s;
}
for(i = 0; i < imax; i += 3) {
b10 = (_getbyte(s,i) << 16) | (_getbyte(s,i+1) << 8) | _getbyte(s,i+2);
x.push(_ALPHA.charAt(b10 >> 18));
x.push(_ALPHA.charAt((b10 >> 12) & 0x3F));
x.push(_ALPHA.charAt((b10 >> 6) & 0x3F));
x.push(_ALPHA.charAt(b10 & 0x3F));
}
switch (s.length -imax) {
case 1:
b10 = _getbyte(s,i) << 16;
x.push(_ALPHA.charAt(b10 >> 18) + _ALPHA.charAt((b10 >> 12) & 0x3F) + _PADCHAR + _PADCHAR);
break;
case 2:
b10 = (_getbyte(s,i) << 16) (_getbyte(s,i+1) << 8);
x.push(_ALPHA.charAt(b10 >> 18) + _ALPHA.charAt((b10 >> 12) & 0x3F) + _ALPHA.charAt((b10 >> 6) & 0x3f) + _PADCHAR);
break;
}
return x.join("");
}
return {
decode: _decode,
encode: _encode,
VERSION: _VERSION
};
}(jQuery));
$('#base64-encode #submit').click(function() {
base64_encoder(base64_getSelected());
});
$('#base64-encode .radio-inline').change(function() {
$('#base64-encode #submit').text(base64_getSelected());
if(base64_getSelected() == '<?= lang('base64_encode'); ?>') {
var input = '<?= lang('base64_input2'); ?>';
var output = '<?= lang('base64_output2'); ?>';
} else if (base64_getSelected() == '<?= lang('base64_decode'); ?>') {
var input = '<?= lang('base64_input3'); ?>';
var output = '<?= lang('base64_output3'); ?>';
}
$('#base64-encode #input').attr('placeholder', input);
$('#base64-encode #output').attr('placeholder', output);
});
var base64_getSelected = function() {
var selectedMethod = "";
var selected = $("input[type='radio'][name=encodeDecode]:checked");
if(selected.length > 0) {
selectedMethod = selected.val();
}
return selectedMethod;
}
var base64_encoder = function(selectedMethod) {
var text = $('#base64-encode #input').val();
if(selectedMethod == '<?= lang('base64_encode'); ?>') {
var output = $.base64.encode(text);
} else {
var output = $.base64.decode(text);
}
$('#base64-encode #output').text(output);
}
</script>
<?php }?>