PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.4.2
Fluent Support – Helpdesk & Customer Support Ticket System v1.4.2
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Http / Controllers / SettingsController.php

SettingsController.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.4.2, at app/Http/Controllers/SettingsController.php

349 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Http\Controllers;
4
5
6 use FluentSupport\App\Models\MailBox;
7 use FluentSupport\App\Models\Meta;
8 use FluentSupport\App\Services\EmailNotification\Settings;
9 use FluentSupport\App\Services\Helper;
10 use FluentSupport\Framework\Request\Request;
11
12 class SettingsController extends Controller
13 {
14 public function getSettings(Request $request)
15 {
16 $settingsKey = $request->get('settings_key');
17
18 return (new Settings)->get($settingsKey);
19 }
20
21 public function getIntegrationSettings(Request $request)
22 {
23 $settings = Meta::where('object_type', 'integration_settings')->get();
24 $integrationSettings = [];
25 foreach ($settings as $index => $setting) {
26 $data = maybe_unserialize($setting->value);
27 if (!empty($data['status']) && $data && $data['status'] == 'yes') {
28 $integrationSettings[] = $setting->key;
29 }
30 }
31 return $integrationSettings;
32 }
33
34 public function saveSettings(Request $request)
35 {
36 $settingsKey = $request->get('settings_key');
37 $settings = wp_unslash($request->get('settings'));
38
39 (new Settings)->save($settingsKey, $settings);
40
41 return [
42 'message' => __('Settings has been updated', 'fluent-support')
43 ];
44 }
45
46 public function getPages()
47 {
48 return [
49 'pages' => Helper::getWPPages()
50 ];
51 }
52
53 public function setupPortal(Request $request)
54 {
55 $mailbox = $request->get('mailbox');
56 $this->validate($mailbox, [
57 'name' => 'required',
58 'email' => 'required|email',
59 'box_type' => 'required'
60 ]);
61
62 $settings = $request->get('global_settings');
63
64 $createPage = $settings['create_portal_page'] == 'yes';
65
66 if (!$createPage && empty($settings['portal_page_id'])) {
67 return $this->sendError([
68 'message' => __('Please select a page or enable create page', 'fluent-support')
69 ]);
70 }
71
72 if ($createPage) {
73 // we have to created the page
74 $page_id = wp_insert_post(
75 array(
76 'comment_status' => 'close',
77 'ping_status' => 'close',
78 'post_author' => get_current_user_id(),
79 'post_title' => __('Support Portal', 'fluent-support'),
80 'post_status' => 'publish',
81 'post_content' => '[fluent_support_portal]',
82 'post_type' => 'page'
83 )
84 );
85 } else {
86 $page_id = intval($settings['portal_page_id']);
87 }
88
89 $newMailBox = MailBox::first();
90 if (!$newMailBox) {
91 $mailbox['is_default'] = 'yes';
92 $mailbox['created_by'] = get_current_user_id();
93 $mailbox['settings']['admin_email_address'] = $mailbox['email'];
94 $newMailBox = MailBox::create($mailbox);
95 }
96
97 $settingsClass = new Settings();
98 $globalSettings = $settingsClass->globalBusinessSettings();
99
100 $globalSettings['portal_page_id'] = $page_id;
101
102 $settingsClass->save('global_business_settings', $globalSettings);
103
104 return [
105 'mailbox' => $newMailBox,
106 'global_settings' => $globalSettings,
107 'mailboxes' => MailBox::select(['id', 'name', 'settings'])->get()
108 ];
109
110 }
111
112 public function getFluentCRMSettings(Request $request)
113 {
114 if (defined('FLUENTCRM')) {
115 $settingDefault = [
116 'enabled' => 'no',
117 'default_status' => 'subscribed',
118 'assigned_list' => '',
119 'assigned_tags' => []
120 ];
121
122 $settings = Helper::getOption('_fluentcrm_intergration_settings');
123
124 $settings = wp_parse_args($settings, $settingDefault);
125
126 $settingsFields = [
127 'enabled' => [
128 'type' => 'inline-checkbox',
129 'true_label' => 'yes',
130 'false_label' => 'no',
131 'checkbox_label' => __('Enable FluentCRM Integration', 'fluent-support')
132 ],
133 'default_status' => [
134 'type' => 'input-radio',
135 'label' => __('Default status for new contacts', 'fluent-support'),
136 'options' => [
137 [
138 'id' => 'subscribed',
139 'label' => __('Subscribed', 'fluent-support')
140 ],
141 [
142 'id' => 'pending',
143 'label' => __('Pending', 'fluent-support')
144 ]
145 ],
146 'dependency' => [
147 'depends_on' => 'enabled',
148 'operator' => '=',
149 'value' => 'yes'
150 ],
151 'inline_help' => __('Select the default status for new contacts. If you select pending and it\'s a new contact then a double optin email will be sent', 'fluent-support')
152 ],
153 'assigned_list' => [
154 'type' => 'input-options',
155 'label' => __('Add to FluentCRM list (optional)', 'fluent-crm'),
156 'options' => \FluentCrm\App\Models\Lists::select(['id', 'title'])->orderBy('title', 'ASC')->get(),
157 'dependency' => [
158 'depends_on' => 'enabled',
159 'operator' => '=',
160 'value' => 'yes'
161 ],
162 ],
163 'assigned_tags' => [
164 'type' => 'input-options',
165 'multiple' => true,
166 'label' => __('Add to Tags', 'fluent-crm'),
167 'options' => \FluentCrm\App\Models\Tag::select(['id', 'title'])->orderBy('title', 'ASC')->get(),
168 'dependency' => [
169 'depends_on' => 'enabled',
170 'operator' => '=',
171 'value' => 'yes'
172 ]
173 ]
174 ];
175
176 return [
177 'is_installed' => true,
178 'settings' => $settings,
179 'settings_fields' => $settingsFields,
180 'fluentcrm_logo' => FLUENT_SUPPORT_PLUGIN_URL.'assets/images/fluentcrm-logo.svg'
181 ];
182 }
183
184 return [
185 'is_installed' => false,
186 'fluentcrm_logo' => FLUENT_SUPPORT_PLUGIN_URL.'assets/images/fluentcrm-logo.svg'
187 ];
188
189 }
190
191 public function installFluentCRM()
192 {
193
194 if (defined('FLUENTCRM')) {
195 return [
196 'is_installed' => true,
197 'message' => __('FluentCRM plugin has been installed and activated successfully', 'fluent-support')
198 ];
199 }
200
201 if (!current_user_can('install_plugins')) {
202 return $this->sendError([
203 'message' => __('Sorry! you do not have permission to install plugin', 'fluent-crm')
204 ]);
205 }
206
207 $plugin_id = 'fluent-connect';
208 $plugin = [
209 'name' => 'Fluent CRM',
210 'repo-slug' => 'fluent-crm',
211 'file' => 'fluent-crm.php',
212 ];
213
214 $this->backgroundInstaller($plugin, $plugin_id);
215
216 if (defined('FLUENTCRM')) {
217 return [
218 'is_installed' => true,
219 'message' => __('FluentCRM plugin has been installed and activated successfully', 'fluent-support')
220 ];
221 } else {
222 return $this->sendError([
223 'message' => __('Sorry! FluentCRM could not be installed. Please install manually', 'fluent-support')
224 ]);
225 }
226 }
227
228 private function backgroundInstaller($plugin_to_install, $plugin_id)
229 {
230 if (!empty($plugin_to_install['repo-slug'])) {
231 require_once ABSPATH . 'wp-admin/includes/file.php';
232 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
233 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
234 require_once ABSPATH . 'wp-admin/includes/plugin.php';
235
236 WP_Filesystem();
237
238 $skin = new \Automatic_Upgrader_Skin();
239 $upgrader = new \WP_Upgrader($skin);
240 $installed_plugins = array_reduce(array_keys(\get_plugins()), array($this, 'associate_plugin_file'), array());
241 $plugin_slug = $plugin_to_install['repo-slug'];
242 $plugin_file = isset($plugin_to_install['file']) ? $plugin_to_install['file'] : $plugin_slug . '.php';
243 $installed = false;
244 $activate = false;
245
246 // See if the plugin is installed already.
247 if (isset($installed_plugins[$plugin_file])) {
248 $installed = true;
249 $activate = !is_plugin_active($installed_plugins[$plugin_file]);
250 }
251
252 // Install this thing!
253 if (!$installed) {
254 // Suppress feedback.
255 ob_start();
256
257 try {
258 $plugin_information = plugins_api(
259 'plugin_information',
260 array(
261 'slug' => $plugin_slug,
262 'fields' => array(
263 'short_description' => false,
264 'sections' => false,
265 'requires' => false,
266 'rating' => false,
267 'ratings' => false,
268 'downloaded' => false,
269 'last_updated' => false,
270 'added' => false,
271 'tags' => false,
272 'homepage' => false,
273 'donate_link' => false,
274 'author_profile' => false,
275 'author' => false,
276 ),
277 )
278 );
279
280 if (is_wp_error($plugin_information)) {
281 throw new \Exception($plugin_information->get_error_message());
282 }
283
284 $package = $plugin_information->download_link;
285 $download = $upgrader->download_package($package);
286
287 if (is_wp_error($download)) {
288 throw new \Exception($download->get_error_message());
289 }
290
291 $working_dir = $upgrader->unpack_package($download, true);
292
293 if (is_wp_error($working_dir)) {
294 throw new \Exception($working_dir->get_error_message());
295 }
296
297 $result = $upgrader->install_package(
298 array(
299 'source' => $working_dir,
300 'destination' => WP_PLUGIN_DIR,
301 'clear_destination' => false,
302 'abort_if_destination_exists' => false,
303 'clear_working' => true,
304 'hook_extra' => array(
305 'type' => 'plugin',
306 'action' => 'install',
307 ),
308 )
309 );
310
311 if (is_wp_error($result)) {
312 throw new \Exception($result->get_error_message());
313 }
314
315 $activate = true;
316
317 } catch (\Exception $e) {
318 }
319
320 // Discard feedback.
321 ob_end_clean();
322 }
323
324 wp_clean_plugins_cache();
325
326 // Activate this thing.
327 if ($activate) {
328 try {
329 $result = activate_plugin($installed ? $installed_plugins[$plugin_file] : $plugin_slug . '/' . $plugin_file);
330
331 if (is_wp_error($result)) {
332 throw new \Exception($result->get_error_message());
333 }
334 } catch (\Exception $e) {
335 }
336 }
337 }
338 }
339
340 private function associate_plugin_file($plugins, $key)
341 {
342 $path = explode('/', $key);
343 $filename = end($path);
344 $plugins[$filename] = $key;
345 return $plugins;
346 }
347
348 }
349