Skip to content

Commit f660e55

Browse files
committed
fix rebase missin brace, fix cs and ci
1 parent d23acf1 commit f660e55

File tree

5 files changed

+75
-71
lines changed

5 files changed

+75
-71
lines changed

api/admin.php

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
$defaultConfig = $configurationService->getDefaultConfiguration();
3232

3333
$data = ArrayUtility::replaceBooleanValues($_POST);
34-
$action = isset($data['type']) ? $data['type'] : null;
34+
$action = $data['type'] ?? null;
3535

3636
// Reset
3737
if ($action === 'reset') {
@@ -260,59 +260,59 @@
260260
if ($newConfig['collage']['enabled']) {
261261
$collageConfigFilePath = CollageLayoutScanner::getCollageConfigPath($newConfig['collage']['layout']); // , $newConfig['collage']['orientation']
262262

263-
if ($collageConfigFilePath !== null) {
264-
$collageJson = json_decode((string)file_get_contents($collageConfigFilePath), true);
263+
if ($collageConfigFilePath !== null) {
264+
$collageJson = json_decode((string)file_get_contents($collageConfigFilePath), true);
265265

266-
if (is_array($collageJson)) {
267-
if (isset($collageJson['layout']) && !empty($collageJson['layout'])) {
268-
$layoutConfigArray = $collageJson['layout'];
266+
if (is_array($collageJson)) {
267+
if (!empty($collageJson['layout'])) {
268+
$layoutConfigArray = $collageJson['layout'];
269269

270-
if (array_key_exists('placeholder', $collageJson)) {
271-
$newConfig['collage']['placeholder'] = $collageJson['placeholder'];
272-
}
273-
if (array_key_exists('placeholderposition', $collageJson)) {
274-
$newConfig['collage']['placeholderposition'] = $collageJson['placeholderposition'];
275-
}
276-
if (array_key_exists('placeholderpath', $collageJson)) {
277-
$newConfig['collage']['placeholderpath'] = $collageJson['placeholderpath'];
270+
if (array_key_exists('placeholder', $collageJson)) {
271+
$newConfig['collage']['placeholder'] = $collageJson['placeholder'];
272+
}
273+
if (array_key_exists('placeholderposition', $collageJson)) {
274+
$newConfig['collage']['placeholderposition'] = $collageJson['placeholderposition'];
275+
}
276+
if (array_key_exists('placeholderpath', $collageJson)) {
277+
$newConfig['collage']['placeholderpath'] = $collageJson['placeholderpath'];
278+
}
279+
} else {
280+
$layoutConfigArray = $collageJson;
278281
}
279-
} else {
280-
$layoutConfigArray = $collageJson;
281-
}
282-
283-
// Calculate collage limit
284-
if (str_starts_with($collageJson['name'], '2x')) {
285-
$newConfig['collage']['limit'] = (int) ceil(count($layoutConfigArray) / 2);
286-
} else {
287-
$newConfig['collage']['limit'] = count($layoutConfigArray);
288-
}
289-
error_log('DEBUG: admin.php - limit: ' . $newConfig['collage']['limit']);
290282

291-
292-
// If there is a collage placeholder whithin the correct range (0 < placeholderposition <= collage limit), we need to decrease the collage limit by 1
293-
if ($newConfig['collage']['placeholder']) {
294-
$collagePlaceholderPosition = (int) $newConfig['collage']['placeholderposition'];
295-
if ($collagePlaceholderPosition > 0 && $collagePlaceholderPosition <= $newConfig['collage']['limit']) {
296-
$newConfig['collage']['limit'] = $newConfig['collage']['limit'] - 1;
283+
// Calculate collage limit
284+
if (str_starts_with($collageJson['name'], '2x')) {
285+
$newConfig['collage']['limit'] = (int)ceil(count($layoutConfigArray) / 2);
297286
} else {
298-
$newConfig['collage']['placeholder'] = false;
299-
$logger->debug('Placeholder position not in range. Placeholder disabled.');
287+
$newConfig['collage']['limit'] = count($layoutConfigArray);
300288
}
289+
error_log('DEBUG: admin.php - limit: ' . $newConfig['collage']['limit']);
290+
291+
// If there is a collage placeholder whithin the correct range (0 < placeholderposition <= collage limit), we need to decrease the collage limit by 1
292+
if ($newConfig['collage']['placeholder']) {
293+
$collagePlaceholderPosition = (int)$newConfig['collage']['placeholderposition'];
294+
if ($collagePlaceholderPosition > 0 && $collagePlaceholderPosition <= $newConfig['collage']['limit']) {
295+
$newConfig['collage']['limit'] = $newConfig['collage']['limit'] - 1;
296+
} else {
297+
$newConfig['collage']['placeholder'] = false;
298+
$logger->debug('Placeholder position not in range. Placeholder disabled.');
299+
}
301300

302-
if ($newConfig['collage']['placeholderpath'] === '') {
303-
$newConfig['collage']['placeholder'] = false;
304-
$logger->debug('Collage Placeholder is empty. Collage Placeholder disabled.');
301+
if ($newConfig['collage']['placeholderpath'] === '') {
302+
$newConfig['collage']['placeholder'] = false;
303+
$logger->debug('Collage Placeholder is empty. Collage Placeholder disabled.');
304+
}
305305
}
306+
} else {
307+
$newConfig['collage']['enabled'] = false;
308+
$logger->debug('No valid collage json found. Collage disabled.');
306309
}
307-
} else {
308-
$newConfig['collage']['enabled'] = false;
309-
$logger->debug('No valid collage json found. Collage disabled.');
310310
}
311-
}
312-
if ($newConfig['collage']['limit'] < 1) {
313-
$newConfig['collage']['enabled'] = false;
311+
if ($newConfig['collage']['limit'] < 1) {
312+
$newConfig['collage']['enabled'] = false;
314313
$newConfig['collage']['limit'] = $defaultConfig['collage']['limit'];
315-
$logger->debug('Invalid collage limit, must be 1 or greater. Collage disabled.');
314+
$logger->debug('Invalid collage limit, must be 1 or greater. Collage disabled.');
315+
}
316316
}
317317

318318
if ($newConfig['picture']['take_frame'] && $newConfig['picture']['frame'] === '') {

lib/configsetup.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@
861861
'type' => 'select',
862862
'name' => 'collage[layout]',
863863
'data-theme-field' => 'true',
864-
'options_html' => CollageLayoutScanner::getLayoutSelectOptionsHtml($config['collage']['layout'] ?? $defaultConfig['collage']['layout']),
864+
'options_html' => CollageLayoutScanner::getLayoutSelectOptionsHtml($config['collage']['layout'] ?? $defaultConfig['collage']['layout']),
865865
],
866866
'collage_orientation' => [
867867
'view' => 'basic',

src/Collage.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ public static function createCollage(array $config, array $srcImagePaths, string
9595
} else {
9696
$layoutConfigArray = $collageJson;
9797
}
98-
} else {
99-
return false;
10098
}
10199
}
102100

src/Configuration/Section/CollageConfiguration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public static function getNode(): NodeDefinition
4242
->validate()
4343
->ifTrue(function ($value) {
4444
if (!is_string($value) || empty($value)) {
45-
return true;
45+
return true;
4646
}
47-
$absolutePath = CollageLayoutScanner::getCollageConfigPath($value);
47+
$absolutePath = CollageLayoutScanner::getCollageConfigPath($value);
4848
return $absolutePath === null;
4949
})
5050
->thenInvalid('The collage layout "%s" does not exist or is invalid.')

src/Utility/CollageLayoutScanner.php

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Photobooth\Utility;
44

5-
use Photobooth\Utility\PathUtility;
65
use Photobooth\Service\LanguageService;
76

87
class CollageLayoutScanner
@@ -29,15 +28,15 @@ public static function scanLayouts(): array
2928

3029
// Initialize the main group key in $layoutFiles early
3130
$layoutFiles[$mainGroupKey] = [];
32-
31+
3332
// Ensure the base directory exists, create if it's a 'private' one and missing
3433
if (!is_dir($absoluteBaseDir)) {
35-
if ($mainGroupKey === 'private') {
34+
if ($mainGroupKey === 'private') {
3635
try {
3736
mkdir($absoluteBaseDir, 0777, true);
3837
} catch (\Exception $e) {
3938
error_log('CollageLayoutScanner: Failed to create base directory: ' . $absoluteBaseDir . ' - ' . $e->getMessage());
40-
continue;
39+
continue;
4140
}
4241
} else {
4342
continue; // Skip if 'template' base dir doesn't exist (expected to be present)
@@ -52,18 +51,18 @@ public static function scanLayouts(): array
5251

5352
// Ensure the subdirectory exists, create if it's in a 'private' context and missing
5453
if (!is_dir($subDirPath)) {
55-
if ($mainGroupKey === 'private') {
54+
if ($mainGroupKey === 'private') {
5655
try {
5756
mkdir($subDirPath, 0777, true);
5857
} catch (\Exception $e) {
5958
error_log('CollageLayoutScanner: Failed to create subdirectory: ' . $subDirPath . ' - ' . $e->getMessage());
60-
continue;
59+
continue;
6160
}
6261
} else {
6362
continue; // Skip if 'template' subdir doesn't exist (expected to be present)
6463
}
6564
}
66-
65+
6766
// If directory exists (or was created), scan it
6867
// Pass the mainGroupKey AND the subGroupName to build the nested structure
6968
self::scanDirectory($subDirPath, $layoutFiles[$mainGroupKey], $subGroupName, $mainGroupKey);
@@ -84,6 +83,10 @@ public static function scanLayouts(): array
8483
private static function scanDirectory(string $directory, array &$layoutFiles, string $subGroupKey, string $mainGroupKey): void
8584
{
8685
$files = glob($directory . DIRECTORY_SEPARATOR . '*.json');
86+
if ($files === false) {
87+
return;
88+
}
89+
8790
foreach ($files as $filePath) {
8891
$fileContent = file_get_contents($filePath);
8992
if ($fileContent === false) {
@@ -97,8 +100,8 @@ private static function scanDirectory(string $directory, array &$layoutFiles, st
97100
continue;
98101
}
99102

100-
$layoutId = basename($filePath, '.json');
101-
103+
$layoutId = basename($filePath, '.json');
104+
102105
$layoutName = $layoutConfig['name'] ?? $layoutId;
103106

104107
$refFilePath = $mainGroupKey . '/collage/' . $subGroupKey . '/' . $layoutId;
@@ -108,9 +111,9 @@ private static function scanDirectory(string $directory, array &$layoutFiles, st
108111
$layoutFiles[$subGroupKey][$layoutId] = [
109112
'id' => $layoutId,
110113
'name' => $layoutName,
111-
'description' => $layoutConfig['description'] ?? '',
114+
'description' => $layoutConfig['description'] ?? '',
112115
'author' => $layoutConfig['author'] ?? 'Unknown',
113-
'ref_file_path' => $refFilePath,
116+
'ref_file_path' => $refFilePath,
114117
'aspect_ratio' => $layoutConfig['aspect_ratio'] ?? '',
115118
'width' => $layoutConfig['width'] ?? '',
116119
'height' => $layoutConfig['height'] ?? '',
@@ -164,7 +167,7 @@ private static function groupAndTranslateLayouts(array $rawLayoutFiles): array
164167
}
165168
}
166169
}
167-
170+
168171
return $groupedLayouts;
169172
}
170173

@@ -179,6 +182,10 @@ public static function getLayoutData(string $logicalReferencePath): ?array
179182
{
180183
$AbsFilePath = self::getCollageConfigPath($logicalReferencePath);
181184

185+
if ($AbsFilePath === null) {
186+
return null;
187+
}
188+
182189
$fileContent = file_get_contents($AbsFilePath);
183190

184191
if ($fileContent === false) {
@@ -192,17 +199,16 @@ public static function getLayoutData(string $logicalReferencePath): ?array
192199
return [];
193200
}
194201

195-
$layoutId = basename($AbsFilePath, '.json');
196-
197-
$layoutName = $layoutConfig['name'] ?? $layoutId;
202+
$layoutId = basename($AbsFilePath, '.json');
203+
204+
$layoutName = $layoutConfig['name'] ?? $layoutId;
198205

199-
200206
$layoutData = [
201207
'id' => $layoutId,
202208
'name' => $layoutName,
203-
'ref_file_path' => $logicalReferencePath,
209+
'ref_file_path' => $logicalReferencePath,
204210
];
205-
211+
206212
$layoutData = array_merge($layoutConfig, $layoutData);
207213

208214
return $layoutData;
@@ -223,7 +229,7 @@ public static function getLayoutSelectOptionsHtml(?string $currentSelectedPath =
223229

224230
foreach ($designes as $mainGroupTitle => $subGroups) {
225231
$optionsHtml .= '<optgroup label="' . htmlspecialchars($mainGroupTitle, ENT_QUOTES) . '">';
226-
232+
227233
// Sort subgroups by their translated titles to ensure consistent order
228234
ksort($subGroups);
229235

@@ -234,13 +240,13 @@ public static function getLayoutSelectOptionsHtml(?string $currentSelectedPath =
234240
}
235241

236242
// Sort the layouts within the subgroup by their name
237-
uasort($layouts, function($a, $b) {
243+
uasort($layouts, function ($a, $b) {
238244
return strcmp($a['name'] ?? $a['id'], $b['name'] ?? $b['id']);
239245
});
240246

241247
foreach ($layouts as $layoutId => $layoutData) {
242248
$selected = ($layoutData['ref_file_path'] === $currentSelectedPath) ? ' selected="selected"' : '';
243-
249+
244250
$displayName = htmlspecialchars($layoutData['name'] ?? $layoutData['id'] ?? '', ENT_QUOTES);
245251

246252
$optionsHtml .= '<option value="' . htmlspecialchars($layoutData['ref_file_path'], ENT_QUOTES) . '"' . $selected . '>';
@@ -265,14 +271,14 @@ public static function getCollageConfigPath(string $logicalReferencePath): ?stri
265271
{
266272
// Add the .json extension
267273
$fullPathWithExtension = $logicalReferencePath . '.json';
268-
274+
269275
// Let PathUtility build the absolute path
270276
$absolutePath = PathUtility::getAbsolutePath($fullPathWithExtension);
271277

272278
if (file_exists($absolutePath)) {
273279
return $absolutePath;
274280
}
275-
281+
276282
// Log, falls die Datei nicht gefunden wird, hilfreich für Debugging
277283
error_log('DEBUG: CollageLayoutScanner::getCollageConfigPath - Layout JSON file not found at: ' . $absolutePath);
278284
return null;

0 commit comments

Comments
 (0)