/file.html |
@@ -109,7 +109,7 @@ |
</span> |
</div> |
<div class="input-group"> |
<select id="tags" multiple class="form-control bootstrap-tagsinput tags"></select> |
<select id="tags" multiple class="form-control bootstrap-tagsinput"></select> |
</div> |
<strong class="error text-danger" data-dz-errormessage></strong> |
</div> |
@@ -174,8 +174,8 @@ |
$.get('session.php').then((token) => { |
// Get the template HTML and remove it from the doument |
var previewNode = document |
.querySelector('#template'); |
previewNode.id = ''; |
.querySelector("#template"); |
previewNode.id = ""; |
var previewTemplate = previewNode |
.parentNode |
.innerHTML; |
@@ -182,7 +182,7 @@ |
previewNode |
.parentNode |
.removeChild(previewNode); |
|
|
var myDropzone = new Dropzone('.panel-body', { // Make the whole body a dropzone |
url: 'file.php', // Set the url |
paramName: 'file', |
@@ -200,20 +200,9 @@ |
}).on('sending', (file, xhr, formData) => { |
// Append session token. |
formData.append('token', token); |
|
// Append tags to the form data. |
const tagsBoxID = file |
.previewElement |
.querySelector('.tags') |
.getAttribute('id'); |
|
const tags = $('#' + tagsBoxID) |
.tagsinput('items'); |
|
formData.append('tags', JSON.stringify(tags)); |
}).on('addedfile', (file) => { |
// Hookup the start button. |
file.previewElement.querySelector('.start').onclick = () => { |
// Hookup the start button |
file.previewElement.querySelector(".start").onclick = () => { |
myDropzone.enqueueFile(file); |
}; |
|
@@ -225,15 +214,17 @@ |
|
file |
.previewElement |
.querySelector('#tags') |
.querySelector("#tags") |
.setAttribute('id', tagsBoxID); |
|
$('#' + tagsBoxID).tagsinput('refresh'); |
//$('input').tagsInput('refresh'); |
|
}).on('totaluploadprogress', (progress) => { |
document |
.querySelector('#total-progress .progress-bar') |
.style |
.width = progress + '%'; |
.width = progress + "%"; |
}).on('sending', (file) => { |
// Show the total progress bar when upload starts |
document.querySelector("#total-progress") |
@@ -243,12 +234,12 @@ |
// And disable the start button. |
file |
.previewElement |
.querySelector('.start') |
.setAttribute('disabled', 'disabled'); |
.querySelector(".start") |
.setAttribute("disabled", "disabled"); |
}).on('queuecomplete', (progress) => { |
document.querySelector('#total-progress') |
document.querySelector("#total-progress") |
.style |
.opacity = '0'; |
.opacity = "0"; |
}).on('success', (file, data) => { |
// Serialize JSON to object. |
data = JSON.parse(data); |
@@ -269,7 +260,7 @@ |
|
file |
.previewElement |
.querySelector('#URL') |
.querySelector("#URL") |
.setAttribute('id', boxURLID) |
|
// Set the ID of the delete URL box. |
@@ -279,17 +270,17 @@ |
.substr(2, 9); |
file |
.previewElement |
.querySelector('#deleteURL') |
.value = location.protocol.concat('//') |
.querySelector("#deleteURL") |
.value = location.protocol.concat("//") |
.concat(window.location.hostname) |
.concat('/') |
.concat("/") |
.concat(data.timestamp) |
.concat('/') |
.concat("/") |
.concat(data.hash); |
|
file |
.previewElement |
.querySelector('#deleteURL') |
.querySelector("#deleteURL") |
.setAttribute('id', deleteBoxURLID) |
|
// Set the ID of the URL clipboard button. |
@@ -299,12 +290,12 @@ |
.substr(2, 9); |
file |
.previewElement |
.querySelector('#btn-clipboard') |
.querySelector("#btn-clipboard") |
.setAttribute('data-clipboard-target', '#' + boxURLID) |
|
file |
.previewElement |
.querySelector('#btn-clipboard') |
.querySelector("#btn-clipboard") |
.setAttribute('id', clipButtonID); |
|
new Clipboard('#' + clipButtonID); |
@@ -316,12 +307,12 @@ |
.substr(2, 9); |
file |
.previewElement |
.querySelector('#btn-clipboard-delete') |
.querySelector("#btn-clipboard-delete") |
.setAttribute('data-clipboard-target', '#' + deleteBoxURLID) |
|
file |
.previewElement |
.querySelector('#btn-clipboard-delete') |
.querySelector("#btn-clipboard-delete") |
.setAttribute('id', clipButtonDeleteID); |
|
new Clipboard('#' + clipButtonDeleteID); |
@@ -334,17 +325,17 @@ |
|
file |
.previewElement |
.querySelector('#btn-mailto') |
.querySelector("#btn-mailto") |
.setAttribute('id', mailToButtonID); |
|
file |
.previewElement |
.querySelector('.start') |
.setAttribute('disabled', 'disabled'); |
.querySelector(".start") |
.setAttribute("disabled", "disabled"); |
file |
.previewElement |
.querySelector('.cancel') |
.setAttribute('disabled', 'disabled'); |
.querySelector(".cancel") |
.setAttribute("disabled", "disabled"); |
|
$('#' + mailToButtonID).on('click', () => { |
window.location.href = "mailto:?subject="+ |
@@ -360,7 +351,7 @@ |
|
file |
.previewElement |
.querySelector('#btn-facebook') |
.querySelector("#btn-facebook") |
.setAttribute('id', faceBookButtonID); |
|
switch(data.opengraph) { |
@@ -369,17 +360,17 @@ |
file |
.previewElement |
.querySelector('#' + faceBookButtonID) |
.removeAttribute('disabled'); |
.removeAttribute("disabled"); |
|
// Change the URL when the user clicks the button. |
$('#' + faceBookButtonID).on('click', () => { |
$('#' + boxURLID) |
.val( |
location.protocol.concat('//') |
location.protocol.concat("//") |
.concat(window.location.hostname) |
.concat('/') |
.concat('og') |
.concat('/') |
.concat("/") |
.concat("og") |
.concat("/") |
.concat(data.hash) |
); |
}); |
@@ -389,18 +380,18 @@ |
file |
.previewElement |
.querySelector('#' + faceBookButtonID) |
.setAttribute('disabled', 'disabled'); |
.setAttribute("disabled", "disabled"); |
break; |
} |
}); |
|
document.querySelector('#actions .start').onclick = () => { |
document.querySelector("#actions .start").onclick = () => { |
myDropzone.enqueueFiles( |
myDropzone |
.getFilesWithStatus(Dropzone.ADDED)); |
}; |
|
document.querySelector('#actions .cancel').onclick = () => { |
document.querySelector("#actions .cancel").onclick = () => { |
myDropzone.removeAllFiles(true); |
}; |
}); |
/file.php |
@@ -96,27 +96,32 @@ |
|
## If we have any tags then insert them into the database. |
if(!empty($tags)) { |
## Connect or create the scratch database. |
$db = new PDO('sqlite:db/scratch.sqlite3'); |
## Set the error mode to exceptions. |
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
try { |
|
## Connect or create the scratch database. |
$db = new PDO('sqlite:db/scratch.sqlite3'); |
## Set the error mode to exceptions. |
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
## Begin the transaction |
$db->beginTransaction(); |
|
## Create tags table if it does not exist. |
|
## Create the tags table if it does not exist. |
$db->query('CREATE TABLE IF NOT EXISTS "tags" ("hash" text NOT NULL COLLATE NOCASE, "tag" text COLLATE NOCASE)'); |
|
## Now add all the tags. |
|
## Insert all the tags for the file. |
foreach($tags as $tag) { |
$q = $db->prepare('REPLACE INTO "tags" ("hash", "tag") VALUES(:hash, :tag)'); |
$q->bindParam(':hash', $file); |
$q->bindParam(':tag', $tag); |
$q->execute(); |
$q = $db->prepare("INSERT INTO tags(hash, tag) VALUES(:hash, :tag)"); |
$q->execute( |
array( |
':hash' => $file, |
':name' => $tag |
) |
); |
} |
|
## Commit the transaction. |
$db->commit(); |
} catch (Exception $e) { |
error_log($e); |
## Rollback. |
$db->rollback(); |
} |