Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluentformpro/src/Components/Post/Getter.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace FluentFormPro\Components\Post;
4
+
5
+
6
+
use FluentForm\App\Api\FormProperties;
7
+
use FluentForm\App\Helpers\Helper;
8
+
use FluentForm\Framework\Helpers\ArrayHelper as Arr;
9
+
10
+
if (!defined('ABSPATH')) {
11
+
exit; // Exit if accessed directly.
12
+
}
13
+
14
+
trait Getter
15
+
{
16
+
private static function deleteAttachmentIds($attachmentIds)
17
+
{
18
+
$deletedIds = [];
19
+
foreach ($attachmentIds as $id) {
20
+
if (!$id) continue;
21
+
$id = (int)$id;
22
+
if (wp_delete_attachment($id)){
23
+
$deletedIds[] = $id;
24
+
}
25
+
}
26
+
return $deletedIds;
27
+
}
28
+
29
+
private static function maybeDeleteAndGetExistingAttachmentIds($fieldName, $formData)
30
+
{
31
+
$deleteAttachmentIds = static::maybeDeleteAttachmentIds($fieldName, $formData);
32
+
$existingAttachmentIds = Arr::get($formData, 'existing-attachment-key-'.$fieldName, []);
33
+
if ($existingAttachmentIds) {
34
+
$existingAttachmentIds = array_map('intval', $existingAttachmentIds);
35
+
if ($deleteAttachmentIds) {
36
+
$existingAttachmentIds = array_values(array_diff($existingAttachmentIds, $deleteAttachmentIds));
37
+
}
38
+
}
39
+
return $existingAttachmentIds;
40
+
}
41
+
42
+
private static function maybeDeleteAttachmentIds($fieldName, $formData)
43
+
{
44
+
$deleteAttachmentIds = Arr::get($formData, 'remove-attachment-key-'.$fieldName, []);
45
+
if ($deleteAttachmentIds) {
46
+
$deleteAttachmentIds = static::deleteAttachmentIds($deleteAttachmentIds);
47
+
}
48
+
return $deleteAttachmentIds;
49
+
}
50
+
51
+
private static function resolveCustomMetaFileTypeField($customMetas, $form, $formData)
52
+
{
53
+
if (!$customMetas || !$form || !$formData) return $customMetas;
54
+
55
+
$formFields = (new FormProperties($form))->inputs(['attributes']);
56
+
foreach ($customMetas as $index => $field) {
57
+
$name = Helper::getInputNameFromShortCode(Arr::get($field, 'meta_value', ''));
58
+
if (!$name) continue;
59
+
$formField = Arr::get($formFields, $name);
60
+
if ('file' == Arr::get($formField, 'attributes.type')) {
61
+
static::maybeDeleteAttachmentIds($name, $formData);
62
+
if (!Arr::get($formData, $name)) {
63
+
Arr::forget($customMetas, $index);
64
+
}
65
+
}
66
+
}
67
+
return $customMetas;
68
+
}
69
+
70
+
public static function resolveDateFieldFormat($fields, $form)
71
+
{
72
+
if (!$fields || !$form) return $fields;
73
+
$formFields = (new FormProperties($form))->inputs();
74
+
foreach ($fields as $index => $field) {
75
+
$name = Helper::getInputNameFromShortCode(Arr::get($field, 'field_value', ''));
76
+
if (!$name) continue;
77
+
$formField = Arr::get($formFields, $name);
78
+
if (
79
+
Arr::get($formField, 'element') === 'input_date' &&
80
+
$format = Arr::get($formField, 'raw.settings.date_format')
81
+
) {
82
+
$fields[$index]['format'] = $format;
83
+
}
84
+
}
85
+
return $fields;
86
+
}
87
+
88
+
protected static function maybeResolveProcessedFeedDateFormat($rawFields, $processedFields)
89
+
{
90
+
foreach ($processedFields as $index => &$field) {
91
+
$dateFormat = Arr::get($rawFields, $index . '.format');
92
+
if ($dateFormat) {
93
+
$field['format'] = $dateFormat;
94
+
}
95
+
}
96
+
return $processedFields;
97
+
}
98
+
99
+
private static function getPostType($formId)
100
+
{
101
+
$postSettings = wpFluent()->table('fluentform_form_meta')
102
+
->where('form_id', $formId)
103
+
->where('meta_key', 'post_settings')
104
+
->first()->value;
105
+
106
+
$postSettings = json_decode($postSettings);
107
+
108
+
return $postSettings->post_type;
109
+
}
110
+
111
+
}