PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.13
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.13
2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 1.45 All 41 releases
fluent-boards / app / Services / InstallService.php

InstallService.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.13, at app/Services/InstallService.php

157 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Services;
4
5 class InstallService
6 {
7 /*
8 * NOTE: This is duplicated from OptionsController . I will refactor this later
9 */
10 public static function install($plugin)
11 {
12
13 $acceptedPlugins = [
14 'fluent-crm' => 'fluent-crm.php',
15 'fluentform' => 'fluentform.php',
16 'fluent-support' => 'fluent-support.php',
17 'fluent-smtp' => 'fluent-smtp.php'
18 ];
19
20 if (!isset($acceptedPlugins[$plugin])) {
21 return;
22 }
23
24 $pluginToInstall = [
25 'name' => __('Fluent Plugin', 'fluent-boards'),
26 'repo-slug' => $plugin,
27 'file' => $acceptedPlugins[$plugin],
28 ];
29
30 (new self())->backgroundInstaller($pluginToInstall, $plugin);
31 }
32 private function isPluginInstalled($plugin)
33 {
34 return file_exists(WP_PLUGIN_DIR . '/' . $plugin);
35 }
36
37 private function backgroundInstaller($plugin_to_install, $plugin_id)
38 {
39 if (!empty($plugin_to_install['repo-slug'])) {
40 require_once ABSPATH . 'wp-admin/includes/file.php';
41 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
42 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
43 require_once ABSPATH . 'wp-admin/includes/plugin.php';
44
45 WP_Filesystem();
46
47 $skin = new \Automatic_Upgrader_Skin();
48 $upgrader = new \WP_Upgrader($skin);
49 $installed_plugins = array_reduce(array_keys(\get_plugins()), array($this, 'associate_plugin_file'), array());
50 $plugin_slug = $plugin_to_install['repo-slug'];
51 $plugin_file = isset($plugin_to_install['file']) ? $plugin_to_install['file'] : $plugin_slug . '.php';
52 $installed = false;
53 $activate = false;
54
55 // See if the plugin is installed already.
56 if (isset($installed_plugins[$plugin_file])) {
57 $installed = true;
58 $activate = !is_plugin_active($installed_plugins[$plugin_file]);
59 }
60
61 // Install this thing!
62 if (!$installed) {
63 // Suppress feedback.
64 ob_start();
65
66 try {
67 $plugin_information = plugins_api(
68 'plugin_information',
69 array(
70 'slug' => $plugin_slug,
71 'fields' => array(
72 'short_description' => false,
73 'sections' => false,
74 'requires' => false,
75 'rating' => false,
76 'ratings' => false,
77 'downloaded' => false,
78 'last_updated' => false,
79 'added' => false,
80 'tags' => false,
81 'homepage' => false,
82 'donate_link' => false,
83 'author_profile' => false,
84 'author' => false,
85 ),
86 )
87 );
88
89 if (is_wp_error($plugin_information)) {
90 throw new \Exception($plugin_information->get_error_message());
91 }
92
93 $package = $plugin_information->download_link;
94 $download = $upgrader->download_package($package);
95
96 if (is_wp_error($download)) {
97 throw new \Exception($download->get_error_message());
98 }
99
100 $working_dir = $upgrader->unpack_package($download, true);
101
102 if (is_wp_error($working_dir)) {
103 throw new \Exception($working_dir->get_error_message());
104 }
105
106 $result = $upgrader->install_package(
107 array(
108 'source' => $working_dir,
109 'destination' => WP_PLUGIN_DIR,
110 'clear_destination' => false,
111 'abort_if_destination_exists' => false,
112 'clear_working' => true,
113 'hook_extra' => array(
114 'type' => 'plugin',
115 'action' => 'install',
116 ),
117 )
118 );
119
120 if (is_wp_error($result)) {
121 throw new \Exception($result->get_error_message());
122 }
123
124 $activate = true;
125
126 } catch (\Exception $e) {
127 }
128
129 // Discard feedback.
130 ob_end_clean();
131 }
132
133 wp_clean_plugins_cache();
134
135 // Activate this thing.
136 if ($activate) {
137 try {
138 $result = activate_plugin($installed ? $installed_plugins[$plugin_file] : $plugin_slug . '/' . $plugin_file);
139
140 if (is_wp_error($result)) {
141 throw new \Exception($result->get_error_message());
142 }
143 } catch (\Exception $e) {
144 }
145 }
146 }
147 }
148
149 private function associate_plugin_file($plugins, $key)
150 {
151 $path = explode('/', $key);
152 $filename = end($path);
153 $plugins[$filename] = $key;
154 return $plugins;
155 }
156
157 }