]> git.p6c8.net - jirafeau_mojo42.git/blobdiff - lib/functions.js
fix typo in lib/settings.php
[jirafeau_mojo42.git] / lib / functions.js
index 8922e0e820ff99bb2192c6b65349e27296be518c..e3800158e51241f291d2cb7d678599e6a4e885f2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Jirafeau, your web file repository
 /*
  *  Jirafeau, your web file repository
- *  Copyright (C) 2012  Jerome Jutteau <j.jutteau@gmail.com>
+ *  Copyright (C) 2015  Jerome Jutteau <j.jutteau@gmail.com>
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU Affero General Public License as
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU Affero General Public License as
@@ -18,6 +18,7 @@
 
 function show_link (url, reference, delete_code, crypt_key, date)
 {
 
 function show_link (url, reference, delete_code, crypt_key, date)
 {
+    // Download page if element exists
     var download_link = url + 'f.php?h=' + reference;
     var download_link_href = url + 'f.php?h=' + reference;
     if (crypt_key.length > 0)
     var download_link = url + 'f.php?h=' + reference;
     var download_link_href = url + 'f.php?h=' + reference;
     if (crypt_key.length > 0)
@@ -25,14 +26,71 @@ function show_link (url, reference, delete_code, crypt_key, date)
         download_link += '&amp;k=' + crypt_key;
         download_link_href += '&k=' + crypt_key;
     }
         download_link += '&amp;k=' + crypt_key;
         download_link_href += '&k=' + crypt_key;
     }
+    if (!!document.getElementById('upload_finished_download_page'))
+    {
+        document.getElementById('upload_link').innerHTML = download_link;
+        document.getElementById('upload_link').href = download_link_href;
+    }
+
+    // Is the preview allowed ?
+    if (!!document.getElementById('preview_link'))
+    {
+        document.getElementById('upload_finished_preview').style.display = 'none';
+        var preview_link = url + 'f.php?h=' + reference + '&amp;p=1';
+        var preview_link_href = url + 'f.php?h=' + reference + '&p=1';
+        if (crypt_key.length > 0)
+        {
+            preview_link += '&amp;k=' + crypt_key;
+            preview_link_href += '&k=' + crypt_key;
+        }
+
+        // Test if content can be previewed
+         type = document.getElementById('file_select').files[0].type;
+         if (type.indexOf("image") > -1 ||
+             type.indexOf("audio") > -1 ||
+             type.indexOf("text") > -1 ||
+             type.indexOf("video") > -1)
+         {
+            document.getElementById('preview_link').innerHTML = preview_link;
+            document.getElementById('preview_link').href = preview_link_href;
+            document.getElementById('upload_finished_preview').style.display = '';
+         }
+    }
+
+    // Only show link to password page if password is set
+    document.getElementById('upload_password_page').style.display = 'none';
+    if (document.getElementById('input_key').value.length > 0)
+    {
+        if (!!document.getElementById('upload_finished_download_page'))
+            document.getElementById('upload_finished_download_page').style.display = 'none';
+        document.getElementById('upload_password_page').style.display = '';
+        if (!!document.getElementById('upload_finished_preview'))
+            document.getElementById('upload_finished_preview').style.display = 'none';
+        document.getElementById('upload_direct_download').style.display = 'none';
 
 
+        document.getElementById('password_link').innerHTML = download_link;
+        document.getElementById('password_link').href = download_link_href;
+    }
+    // Direct download link
+    else
+    {
+        var direct_download_link = url + 'f.php?h=' + reference + '&amp;d=1';
+        var direct_download_link_href = url + 'f.php?h=' + reference + '&d=1';
+        if (crypt_key.length > 0)
+        {
+            direct_download_link += '&amp;k=' + crypt_key;
+            direct_download_link_href += '&k=' + crypt_key;
+        }
+        document.getElementById('direct_link').innerHTML = direct_download_link;
+        document.getElementById('direct_link').href = direct_download_link_href;
+    }
+
+    // Delete link
     var delete_link = url + 'f.php?h=' + reference + '&amp;d=' + delete_code;
     var delete_link_href = url + 'f.php?h=' + reference + '&d=' + delete_code;
     var delete_link = url + 'f.php?h=' + reference + '&amp;d=' + delete_code;
     var delete_link_href = url + 'f.php?h=' + reference + '&d=' + delete_code;
-
-    document.getElementById('upload_link').innerHTML = download_link;
-    document.getElementById('upload_link').href = download_link_href;
     document.getElementById('delete_link').innerHTML = delete_link;
     document.getElementById('delete_link').href = delete_link_href;
     document.getElementById('delete_link').innerHTML = delete_link;
     document.getElementById('delete_link').href = delete_link_href;
+
     if (date)
     {
         document.getElementById('date').innerHTML = date;
     if (date)
     {
         document.getElementById('date').innerHTML = date;
@@ -100,6 +158,8 @@ function classic_upload (url, file, time, password, one_time, upload_password)
                     d.setSeconds (d.getSeconds() + 604800);
                 else if (time == 'month')
                     d.setSeconds (d.getSeconds() + 2419200);
                     d.setSeconds (d.getSeconds() + 604800);
                 else if (time == 'month')
                     d.setSeconds (d.getSeconds() + 2419200);
+                else if (time == 'year')
+                    d.setSeconds (d.getSeconds() + 29030400);
                 else
                     return;
                 show_link (url, res[0], res[1], res[2], d.toString());
                 else
                     return;
                 show_link (url, res[0], res[1], res[2], d.toString());
@@ -258,6 +318,8 @@ function async_upload_end (code)
                     d.setSeconds (d.getSeconds() + 604800);
                 else if (async_global_time == 'month')
                     d.setSeconds (d.getSeconds() + 2419200);
                     d.setSeconds (d.getSeconds() + 604800);
                 else if (async_global_time == 'month')
                     d.setSeconds (d.getSeconds() + 2419200);
+                else if (async_global_time == 'year')
+                    d.setSeconds (d.getSeconds() + 29030400);
                 else
                     return;
                 show_link (async_global_url, res[0], res[1], res[2], d.toString());
                 else
                     return;
                 show_link (async_global_url, res[0], res[1], res[2], d.toString());

patrick-canterino.de