@@ -135,7 +135,7 @@ private function handleCopyOrCut(string $action): void
135
135
136
136
$ sql = rex_sql::factory ();
137
137
$ result = $ sql ->getArray ('SELECT * FROM ' . rex::getTablePrefix () . 'article_slice WHERE id=? ' , [$ sliceId ]);
138
- $ row = is_array ( $ result ) && !empty ($ result ) ? $ result [0 ] : null ;
138
+ $ row = !empty ($ result ) ? $ result [0 ] : null ;
139
139
140
140
if (!is_array ($ row )) {
141
141
echo json_encode (['success ' => false , 'message ' => rex_i18n::msg ('bloecks_error_slice_not_found ' )]);
@@ -145,16 +145,16 @@ private function handleCopyOrCut(string $action): void
145
145
$ user = rex::getUser ();
146
146
147
147
$ modulePerm = $ user ? $ user ->getComplexPerm ('modules ' ) : null ;
148
- $ moduleId = is_numeric ( $ row [ ' module_id ' ]) ? ( int ) $ row ['module_id ' ] : 0 ;
148
+ $ moduleId = ( int ) $ row ['module_id ' ];
149
149
150
150
if (!$ user || !$ modulePerm || !method_exists ($ modulePerm , 'hasPerm ' ) || !$ modulePerm ->hasPerm ($ moduleId )) {
151
151
echo json_encode (['success ' => false , 'message ' => rex_i18n::msg ('bloecks_error_no_module_permission ' )]);
152
152
return ;
153
153
}
154
154
155
155
// Check if user has content edit permissions for this slice
156
- $ articleId = is_numeric ( $ row [ ' article_id ' ]) ? ( int ) $ row ['article_id ' ] : 0 ;
157
- $ clangId = is_numeric ( $ row [ ' clang_id ' ]) ? ( int ) $ row ['clang_id ' ] : 0 ;
156
+ $ articleId = ( int ) $ row ['article_id ' ];
157
+ $ clangId = ( int ) $ row ['clang_id ' ];
158
158
159
159
if (!PermissionUtility::hasContentEditPermission ($ articleId , $ clangId , $ moduleId )) {
160
160
echo json_encode (['success ' => false , 'message ' => rex_i18n::msg ('bloecks_error_no_content_permission ' )]);
@@ -186,13 +186,13 @@ private function handleCopyOrCut(string $action): void
186
186
// Get module name
187
187
$ moduleSql = rex_sql::factory ();
188
188
$ moduleResult = $ moduleSql ->getArray ('SELECT name FROM ' . rex::getTablePrefix () . 'module WHERE id=? ' , [$ moduleId ]);
189
- $ moduleRow = is_array ( $ moduleResult ) && !empty ($ moduleResult ) ? $ moduleResult [0 ] : null ;
190
- $ moduleName = ( is_array ( $ moduleRow) && isset ( $ moduleRow [ ' name ' ]) && is_string ( $ moduleRow [ ' name ' ]))
189
+ $ moduleRow = !empty ($ moduleResult ) ? $ moduleResult [0 ] : null ;
190
+ $ moduleName = $ moduleRow
191
191
? $ moduleRow ['name ' ]
192
192
: rex_i18n::msg ('bloecks_error_unknown_module ' );
193
193
194
194
// Create clipboard item
195
- $ sourceRevision = is_numeric ( $ row [ ' revision ' ]) ? ( int ) $ row ['revision ' ] : 0 ;
195
+ $ sourceRevision = ( int ) $ row ['revision ' ];
196
196
$ clipboardItem = [
197
197
'data ' => $ data ,
198
198
'source_slice_id ' => $ sliceId ,
@@ -212,9 +212,6 @@ private function handleCopyOrCut(string $action): void
212
212
213
213
// Always use multi-clipboard system now
214
214
$ multiClipboard = rex_session ('bloecks_multi_clipboard ' , 'array ' , []);
215
- if (!is_array ($ multiClipboard )) {
216
- $ multiClipboard = [];
217
- }
218
215
219
216
// Check if item already exists (by slice_id)
220
217
$ existingIndex = -1 ;
@@ -446,7 +443,7 @@ private function handleMultiPaste(): void
446
443
$ selectedIndices = array_reverse ($ selectedIndices );
447
444
}
448
445
449
- $ currentTargetSlice = $ targetSlice ;
446
+ $ currentTargetSlice = ( int ) $ targetSlice ;
450
447
451
448
try {
452
449
foreach ($ selectedIndices as $ index ) {
@@ -461,10 +458,11 @@ private function handleMultiPaste(): void
461
458
462
459
if ($ result ['success ' ]) {
463
460
++$ insertedCount ;
464
- $ newSliceIds [] = $ result ['new_slice_id ' ];
461
+ $ newSliceId = is_numeric ($ result ['new_slice_id ' ]) ? (int ) $ result ['new_slice_id ' ] : 0 ;
462
+ $ newSliceIds [] = $ newSliceId ;
465
463
466
464
// Update target slice to the newly inserted slice for proper stacking
467
- $ currentTargetSlice = $ result [ ' new_slice_id ' ] ;
465
+ $ currentTargetSlice = $ newSliceId ;
468
466
469
467
// If cut, remove from multi-clipboard
470
468
if ('cut ' === $ clipboard ['action ' ]) {
@@ -496,11 +494,12 @@ private function handleMultiPaste(): void
496
494
*/
497
495
private function pasteSingleItem (array $ clipboard , int $ targetSlice , int $ articleId , int $ clang , int $ ctype , ?string $ pastePosition = null ): array
498
496
{
497
+ /** @var array<string, mixed> $data */
499
498
$ data = $ clipboard ['data ' ];
500
499
$ user = rex::getUser ();
501
500
502
501
// Check permissions
503
- $ moduleId = isset ($ data ['module_id ' ]) && is_numeric ($ data ['module_id ' ]) ? (int ) $ data ['module_id ' ] : null ;
502
+ $ moduleId = ( isset ($ data ['module_id ' ]) && is_numeric ($ data ['module_id ' ]) ) ? (int ) $ data ['module_id ' ] : null ;
504
503
if (!PermissionUtility::hasContentEditPermission ($ articleId , $ clang , $ moduleId )) {
505
504
return ['success ' => false , 'message ' => rex_i18n::msg ('bloecks_error_no_content_permission ' )];
506
505
}
@@ -565,11 +564,9 @@ private function pasteSingleItem(array $clipboard, int $targetSlice, int $articl
565
564
$ ins ->setValue ('priority ' , $ priority );
566
565
$ ins ->setValue ('revision ' , $ revision );
567
566
568
- if (is_array ($ data )) {
569
- foreach ($ data as $ k => $ v ) {
570
- if (is_string ($ k )) {
571
- $ ins ->setValue ($ k , $ v );
572
- }
567
+ foreach ($ data as $ k => $ v ) {
568
+ if (is_string ($ v ) || is_int ($ v ) || is_float ($ v ) || is_bool ($ v ) || is_null ($ v )) {
569
+ $ ins ->setValue ($ k , $ v );
573
570
}
574
571
}
575
572
@@ -581,7 +578,7 @@ private function pasteSingleItem(array $clipboard, int $targetSlice, int $articl
581
578
582
579
// If cut, delete original slice
583
580
if ('cut ' === $ clipboard ['action ' ]) {
584
- $ srcId = isset ($ clipboard ['source_slice_id ' ]) && is_numeric ($ clipboard ['source_slice_id ' ]) ? (int ) $ clipboard ['source_slice_id ' ] : 0 ;
581
+ $ srcId = ( isset ($ clipboard ['source_slice_id ' ]) && is_numeric ($ clipboard ['source_slice_id ' ]) ) ? (int ) $ clipboard ['source_slice_id ' ] : 0 ;
585
582
if ($ srcId ) {
586
583
rex_content_service::deleteSlice ($ srcId );
587
584
}
0 commit comments