-
Notifications
You must be signed in to change notification settings - Fork 4
video's in het fotoboek #34
base: master
Are you sure you want to change the base?
Changes from all commits
a49054c
f860f7f
4c4116e
1fb765a
ba6dc9d
2e555d3
1dee761
fac03a1
c91ce99
6f7826e
6443550
e168ad8
31af80d
e51c18d
c2e9de6
32f7530
994b86f
1d90b4a
1948ef5
a08355f
68b98b2
6350218
622e15c
d5e6fdc
8f1e719
91c5e96
8edd08b
d2c1961
c986a56
fdccd8f
0bd656f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
// lock the database/cache for write operations | ||
// WARNING: when this is used within a server (non-CLI), the lock will remain | ||
// when the PHP script has finished. When run from the command-line, the locks | ||
// will be relased by the OS (at least, Linux). See: | ||
// http://stackoverflow.com/questions/12651068/release-of-flock-in-case-of-errors | ||
function lock_db () { | ||
global $cachedir; | ||
// provide a locking mechanism to prevent two processes from simultaneously running | ||
$fp = fopen ($cachedir .'lockfile', 'w'); // create if necessary | ||
if (!$fp) { | ||
echo "Could not acquire lock: unable to create lockfile.\n"; | ||
} | ||
if (!flock($fp, LOCK_EX|LOCK_NB)) { | ||
echo "Another process is already updating the database/cache.\nIf this isn't true, remove {$cachedir}lockfile.\n"; | ||
fclose($fp); | ||
echo "Exiting.\n"; | ||
exit; | ||
} | ||
// $fp is required for unlocking (unlocking may be necessary) | ||
return $fp; | ||
} | ||
|
||
// unlock again (requires file pointer returned by lock_db) | ||
// this isn't really needed when run from the command line | ||
function unlock_db ($fp) { | ||
flock($fp, LOCK_UN); | ||
fclose($fp); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,12 @@ | ||
<?php | ||
require('header.php'); | ||
require('media.php'); | ||
|
||
if(!isset($_GET['foto'])) { | ||
showTextAsImage("Missing parameter"); | ||
} | ||
$row = getUnitByFullPath($_GET['foto'], UNIT_PHOTO); | ||
if(!$row) { | ||
header('HTTP/1.1 404 Not found'); | ||
showTextAsImage('Photo not found'); | ||
} | ||
$media = getUnit(UNIT_PHOTO); | ||
|
||
if(!in_array($row['visibility'], getVisibleVisibilities()) || !isPathVisible($row['path'])) { | ||
header('HTTP/1.1 403 Access denied'); | ||
showTextAsImage('Access denied'); | ||
} | ||
$path = $fotodir . $media['path'] . $media['name']; | ||
|
||
if(!$mime = $extensions[getext($row['name'])]) { | ||
showTextAsImage("Unknown extension"); | ||
} | ||
output($path, $media['name']); | ||
|
||
$path = $fotodir . $row['path'] . $row['name']; | ||
|
||
if(!is_file($path)) { | ||
header('HTTP/1.1 404 Not found'); | ||
showTextAsImage("Image not found"); | ||
} | ||
header('Content-type: image/'. $mime); | ||
header('Pragma: public'); | ||
header('Cache-Control: public'); | ||
header('Last-Modified: '. gmdate('D, d M Y H:i:s', $fmt = filemtime($path)) .' GMT'); | ||
header('Expires: '. gmdate('D, d M Y H:i:s', time()+60*60).' GMT'); | ||
header('Etag: '. md5($path . $fmt)); | ||
readfile($path); | ||
require('footer.php'); | ||
?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,19 @@ | ||
<?php | ||
require('header.php'); | ||
require('media.php'); | ||
|
||
if(!isset($_GET['foto'])) { | ||
header('HTTP/1.1 400 Bad Request'); | ||
showTextAsImage("Missing parameter"); | ||
} | ||
$row = getUnitByFullPath($_GET['foto'], UNIT_PHOTO); | ||
if(!$row) { | ||
header('HTTP/1.1 404 Not Found'); | ||
showTextAsImage('Photo not found'); | ||
} | ||
$media = getUnit(UNIT_PHOTO); | ||
|
||
if(!in_array($row['visibility'], getVisibleVisibilities()) || !isPathVisible($row['path'])) { | ||
header('HTTP/1.1 403 Access denied'); | ||
showTextAsImage('Access denied'); | ||
if ($media['type'] == 'photo') { | ||
$path = $cachedir . $media['path'] . $media['name'] .'_large'; | ||
} else { | ||
if(!$mime = $videoExtensions[$_GET['codec']]) { | ||
header('HTTP/1.1 400 Bad Request'); | ||
} | ||
$path = $cachedir . $media['path'] . $media['name'] .'_'. intval($_GET['res']) .'p.'. $mime; | ||
} | ||
|
||
if(!$mime = $extensions[getext($row['name'])]) { | ||
showTextAsImage("Unknown extension"); | ||
} | ||
output($path, $media['name']); | ||
|
||
$cachepath = $cachedir . $row['path'] . $row['name'] .'_large'; | ||
|
||
if(!is_file($cachepath)) { | ||
header('HTTP/1.1 404 Not Found'); | ||
showTextAsImage("Image not cached", 600); | ||
} | ||
header('Content-type: image/'. $mime); | ||
header('Pragma: public'); | ||
header('Cache-Control: public'); | ||
header('Last-Modified: '. gmdate('D, d M Y H:i:s', $fmt = filemtime($cachepath)) .' GMT'); | ||
header('Expires: '. gmdate('D, d M Y H:i:s', time()+60*60).' GMT'); | ||
header('Etag: '. md5($cachepath . $fmt)); | ||
readfile($cachepath); | ||
require('footer.php'); | ||
?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* Get current unit (album/photo/video), | ||
wrapper for getUnitByFullPath(). | ||
*/ | ||
function getUnit ($flags) { | ||
if(!isset($_GET['foto'])) { | ||
header('HTTP/1.1 400 Bad Request'); | ||
showTextAsImage("Missing parameter"); | ||
} | ||
$row = getUnitByFullPath($_GET['foto'], $flags); | ||
if(!$row) { | ||
header('HTTP/1.1 404 Not Found'); | ||
showTextAsImage('Photo not found'); | ||
} | ||
|
||
if(!in_array($row['visibility'], getVisibleVisibilities()) || !isPathVisible($row['path'])) { | ||
header('HTTP/1.1 403 Access denied'); | ||
showTextAsImage('Access denied'); | ||
} | ||
return $row; | ||
} | ||
|
||
/* Send a file to client. | ||
$path is the path of the file, $name is the original name of the file. | ||
*/ | ||
function output ($path, $name=NULL) { | ||
if(!is_file($path)) { | ||
header('HTTP/1.1 404 Not Found'); | ||
showTextAsImage("Image not cached", 600); | ||
} | ||
|
||
$mime = finfo_file(finfo_open(), $path, FILEINFO_MIME_TYPE); | ||
// hack, as long as webm isn't supported by the magic database, this is needed | ||
if (isset($_GET['codec']) && $_GET['codec'] == 'webm') { | ||
$mime = 'video/webm'; | ||
} | ||
|
||
if ($name) | ||
// send real filename instead of php file name | ||
header('Content-disposition: inline; filename='. $name); | ||
header('Content-type: '. $mime); | ||
header('X-Sendfile: '. $path); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :) |
||
function slider_next() { | ||
location.href = next; | ||
} | ||
|
||
function slider_preload() { | ||
var el=document.createElement('img'); | ||
el.src= preload; | ||
el.style.display = 'none'; | ||
el.alt = 'Fotoslider Preloader'; | ||
document.body.appendChild(el); | ||
} | ||
|
||
// apply change in resolution to <video> | ||
function updateResolution () { | ||
var resolution = document.getElementById('resolution').value; | ||
localStorage.videoResolution = resolution; | ||
var video = document.getElementById('video'); | ||
var codec = null; | ||
for (var i=0; i<codecs.length; i++) { | ||
if (video.canPlayType('video/'+codecs[i])) { | ||
codec = codecs[i]; | ||
} | ||
} | ||
if (!codec) { | ||
// problem! Just choose the first. It probably won't play anyway. | ||
codec = codecs[0]; | ||
} | ||
// workaround for bug in Chrome on Linux (mp4 doesn't play but is still advertized to play) | ||
if (video.canPlayType('video/webm') && navigator.userAgent.indexOf('Linux') && navigator.userAgent.indexOf('Chrome') && codecs.indexOf('webm') != -1) { | ||
codec = 'webm'; | ||
} | ||
// all browsers supporting <video> support querySelector | ||
var src = document.querySelector('source[type="video/'+codec+'"][data-resolution="'+resolution+'"]').src; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is dat standaard javascript? Werkt dat in alle browsers? Gaaf. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ja. Het werkt in alle browsers die There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je zin klopt niet. Bedoel je "die we ondersteunen" of "die het ondersteunen"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oeps. De browsers die |
||
var position = video.currentTime; | ||
var playing = !video.paused; | ||
video.src = src; | ||
video.addEventListener('loadedmetadata', function () { | ||
video.currentTime = position; | ||
if (playing) | ||
video.play(); | ||
}, false); | ||
} | ||
|
||
if (type == 'photo') { | ||
if (sliding) { | ||
setTimeout('slider_next()', slider_timeout*1000); | ||
} | ||
} else if (type == 'video') { | ||
window.addEventListener('DOMContentLoaded', function () { | ||
var video = document.getElementById('video'); | ||
if (document.getElementById('resolution').value != localStorage.videoResolution) { | ||
if (localStorage.videoResolution) | ||
document.getElementById('resolution').value = localStorage.videoResolution; | ||
updateResolution(); | ||
} | ||
if (sliding) { | ||
video.addEventListener('ended', function () { | ||
// don't jump to the next immediately | ||
setTimeout(function () { | ||
if (!video.paused) return; | ||
slider_next(); | ||
}, 1000); | ||
}, false); | ||
} | ||
}, false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wat is de SQL nodig voor de update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ik neem aan iets als dit:
(niet getest! maar zou moeten werken)
Edit: de tweede regel is nu dit:
Deze is wel getest (op de vorige tabelstructuur).
Edit2: extra fix.