Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,12 @@ function isElementHidden($element_class, $setting)
echo '<span class="success"><i class="fa fa-check"></i><span data-i18n="success"></span></span>';
echo '<span class="error"><i class="fa fa-times"></i><span data-i18n="saveerror"></span></span>';
break;
case 'database_rebuild':
echo '<span class="saving"><i class="fa fa-circle-o-notch fa-spin fa-fw"></i><span data-i18n="busy"></span></span>';
echo '<span class="success"><i class="fa fa-check"></i><span data-i18n="success"></span></span>';
echo '<span class="error"><i class="fa fa-times"></i><span data-i18n="saveerror"></span></span>';
default:
echo '<span data-i18n="'.$setting['placeholder'].'"></span>';
echo '<span class="text" data-i18n="'.$setting['placeholder'].'"></span>';
break;
}
echo '</button></div>';
Expand Down
6 changes: 4 additions & 2 deletions api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@
imagedestroy($imageResource);

// insert into database
if ($_POST['style'] !== 'chroma' || ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === true)) {
appendImageToDB($file);
if ($config['database']['enabled']) {
if ($_POST['style'] !== 'chroma' || ($_POST['style'] === 'chroma' && $config['live_keying']['show_all'] === true)) {
appendImageToDB($file);
}
}

// Change permissions
Expand Down
10 changes: 8 additions & 2 deletions api/chromakeying/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
require_once '../../lib/resize.php';

if ($config['picture']['naming'] === 'numbered') {
$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$images = getImagesFromDirectory($config['foldersAbs']['images']);
}
$img_number = count($images);
$files = str_pad(++$img_number, 4, '0', STR_PAD_LEFT);
$name = $files . '.jpg';
Expand Down Expand Up @@ -44,7 +48,9 @@
imagedestroy($imageResource);

// insert into database
appendImageToDB($file);
if ($config['database']['enabled']) {
appendImageToDB($file);
}

// Change permissions
chmod($filename_photo, octdec($picture_permissions));
Expand Down
4 changes: 3 additions & 1 deletion api/deletePhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
}
}

deleteImageFromDB($file);
if ($config['database']['enabled']) {
deleteImageFromDB($file);
}

echo json_encode([
'success' => true,
Expand Down
7 changes: 7 additions & 0 deletions api/rebuildImageDB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
header('Content-Type: application/json');

require_once '../lib/config.php';
require_once '../lib/db.php';

rebuildPictureDB();
6 changes: 5 additions & 1 deletion api/takePic.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ function takePicture($filename) {
if (!empty($_POST['file']) && preg_match('/^[a-z0-9_]+\.jpg$/', $_POST['file'])) {
$name = $_POST['file'];
} elseif ($config['picture']['naming'] === 'numbered') {
$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$images = getImagesFromDirectory($config['foldersAbs']['images']);
}
$img_number = count($images);
$files = str_pad(++$img_number, 4, '0', STR_PAD_LEFT);
$name = $files . '.jpg';
Expand Down
1 change: 1 addition & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// control time in milliseconds until Photobooth reloads automatically
$config['picture']['time_to_live'] = '90000';
$config['picture']['preview_before_processing'] = true;
$config['database']['enabled'] = true;
$config['database']['file'] = 'db';


Expand Down
9 changes: 7 additions & 2 deletions gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
exit(json_encode($resp));
}

$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$images = getImagesFromDirectory($config['foldersAbs']['images']);
}

$imagelist = ($config['gallery']['newest_first'] === true) ? array_reverse($images) : $images;
?>
<!DOCTYPE html>
Expand Down Expand Up @@ -101,4 +106,4 @@
<script src="node_modules/@andreasremdt/simple-translator/dist/umd/translator.min.js"></script>
<script type="text/javascript" src="resources/js/i18n.js"></script>
</body>
</html>
</html>
7 changes: 6 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
require_once('lib/db.php');
require_once('lib/filter.php');

$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$images = getImagesFromDirectory($config['foldersAbs']['images']);
}

$imagelist = ($config['gallery']['newest_first'] === true) ? array_reverse($images) : $images;

if ($config['ui']['style'] === 'modern') {
Expand Down
13 changes: 13 additions & 0 deletions lib/configsetup.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,26 @@
'name' => 'picture[preview_before_processing]',
'value' => $config['picture']['preview_before_processing'],
],
'database_enabled' => [
'view' => 'expert',
'type' => 'checkbox',
'name' => 'database[enabled]',
'value' => $config['database']['enabled'],
],
'database_file' => [
'view' => 'expert',
'type' => 'input',
'placeholder' => $defaultConfig['database']['file'],
'name' => 'database[file]',
'value' => $config['database']['file'],
],
'database_rebuild' => [
'view' => 'expert',
'type' => 'button',
'placeholder' => 'database_rebuild',
'name' => 'DATABASEREBUILDBUTTON',
'value' => 'databaserebuild-btn',
],
'diskusage_button' => [
'view' => 'basic',
'type' => 'button',
Expand Down
31 changes: 31 additions & 0 deletions lib/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

define('DB_FILE', $config['foldersAbs']['data'] . DIRECTORY_SEPARATOR . $config['database']['file'] . '.txt');
define('MAIL_FILE', $config['foldersAbs']['data'] . DIRECTORY_SEPARATOR . $config['mail']['file'] . '.txt');
define('IMG_DIR', $config['foldersAbs']['images']);

function getImagesFromDB() {
// get data from db.txt
Expand All @@ -13,6 +14,17 @@ function getImagesFromDB() {
return [];
}

function getImagesFromDirectory($directory) {
$dh = opendir($directory);

while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
closedir($dh);
$images = preg_grep('/\.(jpg|jpeg|JPG|JPEG)$/i', $files);
return $images;
}

function appendImageToDB($filename) {
$images = getImagesFromDB();

Expand Down Expand Up @@ -47,3 +59,22 @@ function getDBSize() {
}
return 0;
}

function rebuildPictureDB() {
$output = [];
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(IMG_DIR, FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS)) as $value) {
if ($value->isFile()) {
$output[] = [$value->getMTime(), $value->getFilename()];
}
}

usort($output, function ($a, $b) {
return $a[0] > $b[0];
});

if (file_put_contents(DB_FILE, json_encode(array_column($output, 1))) === 'false') {
echo json_encode('error');
} else {
echo json_encode('success');
}
}
6 changes: 5 additions & 1 deletion livechroma.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
require_once('lib/config.php');
require_once('lib/db.php');

$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$images = getImagesFromDirectory($config['foldersAbs']['images']);
}
$imagelist = ($config['gallery']['newest_first'] === true) ? array_reverse($images) : $images;

if ($config['ui']['style'] === 'modern') {
Expand Down
5 changes: 5 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"commands:take_picture_cmd": "Take picture command",
"commands:take_picture_msg": "Success message for take picture",
"current_version": "Current version",
"database_rebuild": "Rebuild",
"degrees": "°",
"delete": "Delete",
"disk_usage": "Disk Usage",
Expand Down Expand Up @@ -96,7 +97,9 @@
"gallery_no_image": "The gallery is still empty. Take some pictures!",
"general": "General",
"general:adminpanel_view": "Admin Options",
"general:database_enabled": "Use database for images",
"general:database_file": "Database file name",
"general:database_rebuild": "Rebuild image database",
"general:dev_enabled": "Dev-Mode",
"general:dev_error_messages": "Show error messages",
"general:dev_reload_on_error": "Automatically reload Photobooth on error",
Expand Down Expand Up @@ -212,7 +215,9 @@
"manual:gallery:pswp_tapToToggleControls": "If enabled, the visibility of controls / buttons is switched by tapping.",
"manual:gallery:pswp_zoomEl": "If enabled, PhotoSwipe zoom button is visible inside gallery.",
"manual:general:adminpanel_view": "Allows to set different views in the admin panel with more (Expert View) or less (Basic View) options accessible",
"manual:general:database_enabled": "If enabled, images will be added to a database which is used by the gallery. If disabled, gallery will read the images folder for images - this could reduce the performance.",
"manual:general:database_file": "Name of the database file.",
"manual:general:database_rebuild": "Rebuild the images database. Normally not required but can be used to fix a corrupted database file.",
"manual:general:dev_enabled": "Enables development mode. Sample pictures will be used instead taking a picture.",
"manual:general:dev_error_messages": "If enabled real error messages are shown on error.",
"manual:general:dev_reload_on_error": "If an error occurs while taking a picture, Photobooth will reload automatically after 5 seconds.",
Expand Down
6 changes: 5 additions & 1 deletion slideshow/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
require_once('../lib/db.php');
require_once('../lib/filter.php');

$images = getImagesFromDB();
if ($config['database']['enabled']) {
$images = getImagesFromDB();
} else {
$images = getImagesFromDirectory($config['foldersAbs']['images']);
}
$imagelist = array_reverse($images);

?>
Expand Down
20 changes: 20 additions & 0 deletions src/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ $(function () {
return false;
});

$('#databaserebuild-btn').on('click', function (e) {
e.preventDefault();
const elem = $(this);
$('#databaserebuild-btn').children('.text').toggle();
elem.addClass('saving');

$.ajax({
url: '../api/rebuildImageDB.php',
success: function (resp) {
elem.removeClass('saving');
elem.addClass(resp);

setTimeout(function () {
elem.removeClass('error success');
$('#databaserebuild-btn').children('.text').toggle();
}, 2000);
}
});
});

$('#checkVersion a').on('click', function (ev) {
ev.preventDefault();

Expand Down