Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluentformpro/src/Components/Post/Bootstrap.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
namespace FluentFormPro\Components\Post;
4
+
5
+
if (!defined('ABSPATH')) {
6
+
exit; // Exit if accessed directly.
7
+
}
8
+
9
+
use FluentForm\App\Services\FormBuilder\ShortCodeParser;
10
+
use FluentForm\Framework\Helpers\ArrayHelper;
11
+
use FluentFormPro\Components\Post\EditorSettings;
12
+
use FluentFormPro\Components\Post\PostFormHandler;
13
+
14
+
class Bootstrap
15
+
{
16
+
public static function boot()
17
+
{
18
+
return new static;
19
+
}
20
+
21
+
public function __construct()
22
+
{
23
+
$isEnabled = $this->isEnabled();
24
+
25
+
add_filter('fluentform/global_addons', function ($addons) use ($isEnabled) {
26
+
$app = wpFluentForm();
27
+
28
+
$addons['postFeeds'] = [
29
+
'title' => __('Post/CPT Creation', 'fluentformpro'),
30
+
'category' => 'wp_core',
31
+
'description' => __('Create post/any cpt on form submission. It will enable many new features including dedicated post fields', 'fluentformpro'),
32
+
'logo' => fluentFormMix('img/integrations/post-creation.png'),
33
+
'enabled' => ($isEnabled) ? 'yes' : 'no'
34
+
];
35
+
36
+
return $addons;
37
+
});
38
+
39
+
if (!$isEnabled) {
40
+
return;
41
+
}
42
+
43
+
$this->registerHooks();
44
+
45
+
$this->registerPostFields();
46
+
}
47
+
48
+
protected function registerHooks()
49
+
{
50
+
add_filter('fluentform/all_forms_vars', function ($settings) {
51
+
$settings['has_post_feature'] = true;
52
+
return $settings;
53
+
});
54
+
55
+
add_filter('fluentform/response_render_taxonomy', [$this, 'formatResponse'], 10, 4);
56
+
57
+
$editorSettings = new EditorSettings;
58
+
59
+
add_action('fluentform/inserted_new_form', [
60
+
$editorSettings, 'onNewFormCreated'
61
+
]);
62
+
63
+
add_filter('fluentform/editor_components', [
64
+
$editorSettings, 'registerEditorTaxonomyFields'
65
+
], 10, 2);
66
+
67
+
add_filter('fluentform/editor_element_settings_placement', [
68
+
$editorSettings, 'elementPlacementSettings'
69
+
]);
70
+
71
+
add_filter('fluentform/form_settings_menu', [
72
+
$editorSettings, 'registerPostFormSettingsMenu'
73
+
], 10, 2);
74
+
75
+
$postFormHandler = new PostFormHandler;
76
+
77
+
add_filter('fluentform/smartcode_group_post', [
78
+
$postFormHandler, 'parsePostShortCodes'
79
+
], 10, 2);
80
+
81
+
add_action('fluentform/render_item_taxonomy', [
82
+
$postFormHandler, 'renderTaxonomyFields'
83
+
], 10, 2);
84
+
85
+
$createPostBeforeFormActions = apply_filters('fluentform/create_post_before_form_actions_processing', true);
86
+
if ($createPostBeforeFormActions) {
87
+
add_action('fluentform/before_form_actions_processing', [
88
+
$postFormHandler, 'onFormSubmissionInserted'
89
+
], 10, 3);
90
+
} else {
91
+
add_action('fluentform/submission_inserted_post_form', [
92
+
$postFormHandler, 'onFormSubmissionInserted'
93
+
], 10, 3);
94
+
}
95
+
96
+
add_action('fluentform/form_element_start', [
97
+
$postFormHandler, 'maybeRenderPostSelectionField'
98
+
], 10, 3);
99
+
100
+
101
+
$postFormPopulate = new PopulatePostForm;
102
+
103
+
add_action('wp_ajax_fluentformpro_get_post_details', [$postFormPopulate, 'getPostDetails']);
104
+
add_action('wp_ajax_nopriv_fluentformpro_get_post_details', [$postFormPopulate, 'getPostDetails']);
105
+
106
+
107
+
add_filter('fluentform/all_editor_shortcodes', function ($shortCodes) {
108
+
$shortCodes[] = [
109
+
'title' => __('Post', 'fluentformpro'),
110
+
'shortcodes' => [
111
+
'{post.ID}' => 'Post ID',
112
+
'{post.post_title}' => 'Post Title',
113
+
'{post.post_permalink}' => 'Post Permalink'
114
+
]
115
+
];
116
+
117
+
return $shortCodes;
118
+
});
119
+
}
120
+
121
+
protected function registerPostFields()
122
+
{
123
+
new \FluentFormPro\Components\Post\Components\PostTitle;
124
+
new \FluentFormPro\Components\Post\Components\PostContent('post_content', 'Post Content', ['content', 'post_content', 'post', 'editor'], 'post');
125
+
new \FluentFormPro\Components\Post\Components\PostExcerpt;
126
+
new \FluentFormPro\Components\Post\Components\FeaturedImage;
127
+
new \FluentFormPro\Components\Post\Components\PostUpdate;
128
+
}
129
+
130
+
private function isEnabled()
131
+
{
132
+
$globalModules = (array)get_option('fluentform_global_modules_status');
133
+
134
+
if ($globalModules) {
135
+
return ArrayHelper::get($globalModules, 'postFeeds') == 'yes';
136
+
}
137
+
138
+
return false;
139
+
}
140
+
141
+
public function formatResponse($response, $field, $form_id, $isHtml)
142
+
{
143
+
if (!$response) {
144
+
return;
145
+
}
146
+
147
+
if (!is_array($response) && !is_numeric($response)) {
148
+
return $response;
149
+
}
150
+
151
+
$options = ArrayHelper::get($field, 'raw.settings.options', []);
152
+
153
+
if (!$options) {
154
+
return fluentImplodeRecursive(', ', $response);
155
+
}
156
+
157
+
$formattedResponse = [];
158
+
159
+
if (!is_array($response)) {
160
+
$response = [$response];
161
+
}
162
+
163
+
foreach ($response as $term_id) {
164
+
if (isset($options[$term_id])) {
165
+
$formattedResponse[] = $options[$term_id];
166
+
} else {
167
+
$formattedResponse[] = $term_id;
168
+
}
169
+
}
170
+
171
+
if (!$isHtml) {
172
+
return fluentImplodeRecursive(', ', $formattedResponse);
173
+
}
174
+
175
+
$html = $html = '<ul class="ff_entry_list">';
176
+
foreach ($formattedResponse as $label => $response) {
177
+
$html .= '<li>' . $response . '</li>';
178
+
}
179
+
$html .= '</ul>';
180
+
return $html;
181
+
}
182
+
}
183
+