Commit a0daba42398968ae5142fc0198cee95f1da03908

Authored by Jean Wasilewski
1 parent d0d663f9

Partial base64 and news deletion

Showing 3 changed files with 143 additions and 1 deletions   Show diff stats
index.php
... ... @@ -18,6 +18,7 @@ require_once("creds.php");
18 18 <script type="text/javascript" src="js/bootstrap.min.js"></script>
19 19 <script type="text/javascript" src="js/whirlpool.min.js"></script>
20 20 <script type="text/javascript" src="js/crep.js"></script>
  21 + <script type="text/javascript" src="js/base64.js"></script>
21 22 </head>
22 23 <body>
23 24 <?php require_once("topnavbar.php");?>
... ...
js/base64.js 0 → 100644
... ... @@ -0,0 +1,135 @@
  1 +var Base64 = {
  2 +
  3 + // private property
  4 + _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  5 +
  6 + // public method for encoding
  7 + encode : function (input) {
  8 + var output = "";
  9 + var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  10 + var i = 0;
  11 +
  12 + input = Base64._utf8_encode(input);
  13 +
  14 + while (i < input.length) {
  15 +
  16 + chr1 = input.charCodeAt(i++);
  17 + chr2 = input.charCodeAt(i++);
  18 + chr3 = input.charCodeAt(i++);
  19 +
  20 + enc1 = chr1 >> 2;
  21 + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  22 + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  23 + enc4 = chr3 & 63;
  24 +
  25 + if (isNaN(chr2)) {
  26 + enc3 = enc4 = 64;
  27 + } else if (isNaN(chr3)) {
  28 + enc4 = 64;
  29 + }
  30 +
  31 + output = output +
  32 + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
  33 + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
  34 +
  35 + }
  36 +
  37 + return output;
  38 + },
  39 +
  40 + // public method for decoding
  41 + decode : function (input) {
  42 + var output = "";
  43 + var chr1, chr2, chr3;
  44 + var enc1, enc2, enc3, enc4;
  45 + var i = 0;
  46 +
  47 + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  48 +
  49 + while (i < input.length) {
  50 +
  51 + enc1 = this._keyStr.indexOf(input.charAt(i++));
  52 + enc2 = this._keyStr.indexOf(input.charAt(i++));
  53 + enc3 = this._keyStr.indexOf(input.charAt(i++));
  54 + enc4 = this._keyStr.indexOf(input.charAt(i++));
  55 +
  56 + chr1 = (enc1 << 2) | (enc2 >> 4);
  57 + chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  58 + chr3 = ((enc3 & 3) << 6) | enc4;
  59 +
  60 + output = output + String.fromCharCode(chr1);
  61 +
  62 + if (enc3 != 64) {
  63 + output = output + String.fromCharCode(chr2);
  64 + }
  65 + if (enc4 != 64) {
  66 + output = output + String.fromCharCode(chr3);
  67 + }
  68 +
  69 + }
  70 +
  71 + output = Base64._utf8_decode(output);
  72 +
  73 + return output;
  74 +
  75 + },
  76 +
  77 + // private method for UTF-8 encoding
  78 + _utf8_encode : function (string) {
  79 + string = string.replace(/\r\n/g,"\n");
  80 + var utftext = "";
  81 +
  82 + for (var n = 0; n < string.length; n++) {
  83 +
  84 + var c = string.charCodeAt(n);
  85 +
  86 + if (c < 128) {
  87 + utftext += String.fromCharCode(c);
  88 + }
  89 + else if((c > 127) && (c < 2048)) {
  90 + utftext += String.fromCharCode((c >> 6) | 192);
  91 + utftext += String.fromCharCode((c & 63) | 128);
  92 + }
  93 + else {
  94 + utftext += String.fromCharCode((c >> 12) | 224);
  95 + utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  96 + utftext += String.fromCharCode((c & 63) | 128);
  97 + }
  98 +
  99 + }
  100 +
  101 + return utftext;
  102 + },
  103 +
  104 + // private method for UTF-8 decoding
  105 + _utf8_decode : function (utftext) {
  106 + var string = "";
  107 + var i = 0;
  108 + var c = c1 = c2 = 0;
  109 +
  110 + while ( i < utftext.length ) {
  111 +
  112 + c = utftext.charCodeAt(i);
  113 +
  114 + if (c < 128) {
  115 + string += String.fromCharCode(c);
  116 + i++;
  117 + }
  118 + else if((c > 191) && (c < 224)) {
  119 + c2 = utftext.charCodeAt(i+1);
  120 + string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
  121 + i += 2;
  122 + }
  123 + else {
  124 + c2 = utftext.charCodeAt(i+1);
  125 + c3 = utftext.charCodeAt(i+2);
  126 + string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
  127 + i += 3;
  128 + }
  129 +
  130 + }
  131 +
  132 + return string;
  133 + }
  134 +
  135 +}
... ...
js/crep.js
... ... @@ -18,9 +18,15 @@ function loadNewDoc(doc) {
18 18 return false
19 19 }
20 20  
  21 +function deleteNewNews()
  22 +{
  23 + if (confirm('Voulez vous vraiment supprimer la news ?'))
  24 + $("#newNews").remove();
  25 +}
  26 +
21 27 function addNews()
22 28 {
23   - var elem = "<div class=\"panel panel-default\"><div class=\"panel-heading\"><h3 class=\"panel-title\"><input type=text class=\"form-control\" placeholder=\"Nouvel article\"/></h3></div><div class=\"panel-body\"><textarea class=\"form-control\"></textarea></div><div class=\"panel-footer\"><p>En cours d'édition</p></div></div>";
  29 + var elem = "<div id=\"newNews\" class=\"panel panel-default\"><div class=\"panel-heading\"><h3 class=\"panel-title\"><input type=text class=\"form-control\" placeholder=\"Nouvel article\"/></h3></div><div class=\"panel-body\"><textarea class=\"form-control\"></textarea></div><div class=\"panel-footer\"><p><button type=\"button\" onClick=\"validNewNews();\" class=\"btn btn-success\">Success</button>&nbsp;<button type=\"button\" onClick=\"deleteNewNews();\" class=\"btn btn-danger\">Annuler</button></p></div></div>";
24 30 $("#mainContainer").append(elem);
25 31 }
26 32  
... ...