PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.0.5
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.0.5
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / widgets / widget-mainwp-widget-plugins.php

widget-mainwp-widget-plugins.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.0.5, at widgets/widget-mainwp-widget-plugins.php

228 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class MainWP_Widget_Plugins {
4
5 public static function getClassName() {
6 return __CLASS__;
7 }
8
9 public static function render() {
10 MainWP_Widget_Plugins::renderWidget( false, false );
11 }
12
13 public function prepare_icons() {
14 include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
15
16 $args = array(
17 'fields' => array(
18 'last_updated' => true,
19 'icons' => true,
20 'active_installs' => true
21 )
22 );
23
24 $api = plugins_api( 'query_plugins', $args );
25
26 if ( is_wp_error( $api ) ) {
27 $this->error = $api;
28 return;
29 }
30
31 $this->items = $api->plugins;
32 }
33
34 public static function renderWidget( $renew, $pExit = true ) {
35 $current_wpid = MainWP_Utility::get_current_wpid();
36 if ( empty( $current_wpid ) ) {
37 return;
38 }
39
40 $sql = MainWP_DB::Instance()->getSQLWebsiteById( $current_wpid );
41 $websites = MainWP_DB::Instance()->query( $sql );
42 $allPlugins = array();
43 if ( $websites ) {
44 $website = @MainWP_DB::fetch_object( $websites );
45 if ( $website && $website->plugins != '' ) {
46 $plugins = json_decode( $website->plugins, 1 );
47 if ( is_array( $plugins ) && count( $plugins ) != 0 ) {
48 foreach ( $plugins as $plugin ) {
49 if ( isset( $plugin[ 'mainwp' ] ) && ( $plugin[ 'mainwp' ] == 'T' ) ) {
50 continue;
51 }
52 $allPlugins[] = $plugin;
53 }
54 }
55 }
56 @MainWP_DB::free_result( $websites );
57 }
58
59 $actived_plugins = MainWP_Utility::getSubArrayHaving( $allPlugins, 'active', 1 );
60 $actived_plugins = MainWP_Utility::sortmulti( $actived_plugins, 'name', 'asc' );
61
62 $inactive_plugins = MainWP_Utility::getSubArrayHaving( $allPlugins, 'active', 0 );
63 $inactive_plugins = MainWP_Utility::sortmulti( $inactive_plugins, 'name', 'asc' );
64
65 $plugins_outdate = array();
66
67 if ( ( count( $allPlugins ) > 0 ) && $website ) {
68
69 $plugins_outdate = json_decode( MainWP_DB::Instance()->getWebsiteOption( $website, 'plugins_outdate_info' ), true );
70 if ( !is_array( $plugins_outdate ) ) {
71 $plugins_outdate = array();
72 }
73
74 $pluginsOutdateDismissed = json_decode( MainWP_DB::Instance()->getWebsiteOption( $website, 'plugins_outdate_dismissed' ), true );
75 if ( is_array( $pluginsOutdateDismissed ) ) {
76 $plugins_outdate = array_diff_key( $plugins_outdate, $pluginsOutdateDismissed );
77 }
78
79 $userExtension = MainWP_DB::Instance()->getUserExtension();
80 $decodedDismissedPlugins = json_decode( $userExtension->dismissed_plugins, true );
81
82 if ( is_array( $decodedDismissedPlugins ) ) {
83 $plugins_outdate = array_diff_key( $plugins_outdate, $decodedDismissedPlugins );
84 }
85 }
86
87 ?>
88
89 <div class="ui grid">
90 <div class="twelve wide column">
91 <h3 class="ui header handle-drag">
92 <?php _e('Plugins', 'mainwp'); ?>
93 <div class="sub header"><?php _e( 'Installed plugins on the child site', 'mainwp' ); ?></div>
94 </h3>
95 </div>
96 <div class="four wide column right aligned">
97 <div class="ui dropdown right mainwp-dropdown-tab">
98 <div class="text"><?php _e( 'Active', 'mainwp' ); ?></div>
99 <i class="dropdown icon"></i>
100 <div class="menu">
101 <a class="item" data-tab="active_plugins" data-value="active_plugins" title="<?php esc_attr_e( 'Active', 'mainwp' ); ?>" href="#"><?php _e( 'Active', 'mainwp' ); ?></a>
102 <a class="item" data-tab="inactive_plugins" data-value="inactive_plugins" title="<?php esc_attr_e( 'Inactive', 'mainwp' ); ?>" href="#"><?php _e( 'Inactive', 'mainwp' ); ?></a>
103 </div>
104 </div>
105 </div>
106 </div>
107
108 <div class="ui section hidden divider"></div>
109
110 <!-- Active Plugins List -->
111 <div id="mainwp-widget-active-plugins" class="ui tab active" data-tab="active_plugins">
112 <div class="ui divided selection list">
113 <?php
114
115 for ( $i = 0; $i < count( $actived_plugins ); $i ++ ) {
116
117 $slug = strip_tags( $actived_plugins[ $i ][ 'slug' ] );
118
119 ?>
120 <div class="item">
121 <input class="pluginSlug" type="hidden" name="slug" value="<?php echo esc_attr( strip_tags( $actived_plugins[ $i ][ 'slug' ] ) ); ?>"/>
122 <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr($website->id); ?>"/>
123 <div class="right floated pluginsAction">
124 <?php if ( mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
125 <a href="#" class="mainwp-plugin-deactivate ui mini button green" data-position="top right" data-tooltip="<?php echo __( 'Deactivate the ', 'mainwp') . esc_html( $actived_plugins[ $i ][ 'name' ] ) . __( ' plugin on the child site.', 'mainwp'); ?>" data-inverted=""><?php _e( 'Deactivate', 'mainwp' ); ?></a>
126 <?php } ?>
127 </div>
128 <div class="middle aligned content">
129 <a href="<?php echo admin_url() . 'plugin-install.php?tab=plugin-information&plugin=' . dirname( strip_tags( $actived_plugins[ $i ][ 'slug' ] ) ) . '&TB_iframe=true&width=640&height=477'; ?>" target="_blank" class="thickbox open-plugin-details-modal" title="More information about <?php echo esc_html( $actived_plugins[ $i ][ 'name' ] ); ?>">
130 <?php echo esc_html( $actived_plugins[ $i ][ 'name' ] . ' ' . $actived_plugins[ $i ][ 'version' ] ); ?>
131 </a>
132 </div>
133 <div class="mainwp-row-actions-working">
134 <i class="notched circle loading icon"></i> <?php _e( 'Please wait...', 'mainwp' ); ?>
135 </div>
136 </div>
137 <?php } ?>
138 </div>
139 </div>
140
141 <!-- Inactive Plugins List -->
142 <div id="mainwp-widget-inactive-plugins" class="ui tab" data-tab="inactive_plugins">
143 <div class="ui middle aligned divided selection list">
144 <?php
145 for ( $i = 0; $i < count( $inactive_plugins ); $i ++ ) {
146
147 $slug = $inactive_plugins[ $i ][ 'slug' ];
148
149 ?>
150 <div class="item">
151 <input class="pluginSlug" type="hidden" name="slug" value="<?php echo esc_attr( strip_tags( $inactive_plugins[ $i ][ 'slug' ] ) ); ?>"/>
152 <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr($website->id); ?>"/>
153 <div class="right floated content pluginsAction">
154 <?php if ( mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) { ?>
155 <a href="#" class="mainwp-plugin-activate ui mini green button" data-position="top right" data-tooltip="<?php echo __( 'Activate the ', 'mainwp') . strip_tags( $inactive_plugins[ $i ][ 'name' ] ) . __( ' plugin on the child site.', 'mainwp'); ?>" data-inverted=""><?php _e( 'Activate', 'mainwp' ); ?></a>
156 <?php } ?>
157 <?php if ( mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) { ?>
158 <a href="#" class="mainwp-plugin-delete ui mini basic button" data-position="top right" data-tooltip="<?php echo __( 'Delete the ', 'mainwp') . strip_tags( $inactive_plugins[ $i ][ 'name' ] ) . __( ' plugin from the child site.', 'mainwp'); ?>" data-inverted=""><?php _e( 'Delete', 'mainwp' ); ?></a>
159 <?php } ?>
160 </div>
161 <div class="middle aligned content">
162 <a href="<?php echo admin_url() . 'plugin-install.php?tab=plugin-information&plugin=' . dirname( $inactive_plugins[ $i ][ 'slug' ] ) . '&TB_iframe=true&width=640&height=477'; ?>" target="_blank" class="thickbox open-plugin-details-modal" title="More information about <?php echo strip_tags($inactive_plugins[ $i ][ 'name' ]); ?>">
163 <?php echo esc_html($inactive_plugins[ $i ][ 'name' ] . ' ' . $inactive_plugins[ $i ][ 'version' ]); ?>
164 </a>
165 </div>
166 <div class="mainwp-row-actions-working">
167 <i class="ui active inline loader tiny"></i> <?php _e( 'Please wait...', 'mainwp' ); ?>
168 </div>
169 </div>
170 <?php } ?>
171 </div>
172 </div>
173
174 <?php
175
176 if ( $pExit == true ) {
177 exit();
178 }
179 }
180
181 public static function activatePlugin() {
182 self::action( 'activate' );
183 die( json_encode( array( 'result' => __( 'Plugin has been activated!', 'mainwp' ) ) ) );
184 }
185
186 public static function deactivatePlugin() {
187 self::action( 'deactivate' );
188 die( json_encode( array( 'result' => __( 'Plugin has been deactivated!', 'mainwp' ) ) ) );
189 }
190
191 public static function deletePlugin() {
192 self::action( 'delete' );
193 die( json_encode( array( 'result' => __( 'Plugin has been permanently deleted!', 'mainwp' ) ) ) );
194 }
195
196 public static function action( $pAction ) {
197 $plugin = $_POST[ 'plugin' ];
198 $websiteIdEnc = $_POST[ 'websiteId' ];
199
200 if ( empty( $plugin ) ) {
201 die( json_encode( array( 'error' => 'Invalid Request!' ) ) );
202 }
203 $websiteId = $websiteIdEnc;
204 if ( !MainWP_Utility::ctype_digit( $websiteId ) ) {
205 die( json_encode( array( 'error' => 'Invalid Request!' ) ) );
206 }
207
208 $website = MainWP_DB::Instance()->getWebsiteById( $websiteId );
209 if ( !MainWP_Utility::can_edit_website( $website ) ) {
210 die( json_encode( array( 'error' => 'You can not edit this website!' ) ) );
211 }
212
213 try {
214 $information = MainWP_Utility::fetchUrlAuthed( $website, 'plugin_action', array(
215 'action' => $pAction,
216 'plugin' => $plugin,
217 ) );
218 } catch ( MainWP_Exception $e ) {
219 die( json_encode( array( 'error' => MainWP_Error_Helper::getErrorMessage( $e ) ) ) );
220 }
221
222 if ( !isset( $information[ 'status' ] ) || ( $information[ 'status' ] != 'SUCCESS' ) ) {
223 die( json_encode( array( 'error' => 'Unexpected error!' ) ) );
224 }
225 }
226
227 }
228