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 / class / class-mainwp-twitter.php

class-mainwp-twitter.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.0.5, at class/class-mainwp-twitter.php

299 lines 10.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class MainWP_Twitter {
4 public static function getClassName() {
5 return __CLASS__;
6 }
7
8 static function get_filter() {
9 return array(
10 'upgrade_everything',
11 'upgrade_all_wp_core',
12 'upgrade_all_plugins',
13 'upgrade_all_themes',
14 'new_post',
15 'new_page',
16 'installing_new_plugin',
17 'installing_new_theme',
18 'create_new_user',
19 );
20 }
21
22 public static function enabledTwitterMessages() {
23 if ( ! get_option( 'mainwp_hide_twitters_message', 0 ) ) {
24 return true;
25 }
26
27 return false;
28 }
29
30 public static function clearAllTwitterMessages() {
31 $filters = self::get_filter();
32 $user_id = get_current_user_id();
33
34 foreach ( $filters as $what ) {
35 $opt_name = 'mainwp_tt_message_' . $what;
36 delete_user_option( $user_id, $opt_name );
37 }
38 }
39
40 static function randomWord() {
41 $words = array(
42 __( 'Awesome', 'mainwp' ),
43 __( 'Fabulous', 'mainwp' ),
44 __( 'Impressive', 'mainwp' ),
45 __( 'Incredible', 'mainwp' ),
46 __( 'Super', 'mainwp' ),
47 __( 'Wonderful', 'mainwp' ),
48 __( 'Wow', 'mainwp' ),
49 );
50
51 return $words[ rand( 0, 6 ) ];
52 }
53
54 static function getNotice( $what, $value ) {
55
56 if ( ! is_array( $value ) || empty( $value['sites'] ) || ! isset( $value['seconds'] ) ) {
57 return '';
58 }
59
60 $message = '';
61 $first_word = self::randomWord();
62 switch ( $what ) {
63 case 'upgrade_everything':
64 $message = $first_word . ', ' . _n( 'you just updated <strong>%d</strong> site', 'you just updated <strong>%d</strong> sites', $value['sites'], 'mainwp' );
65 $message = sprintf( $message, $value['sites'] );
66 break;
67 case 'upgrade_all_wp_core':
68 $message = $first_word . ', ' . _n( 'you just updated <strong>%d</strong> WordPress site', 'you just updated <strong>%d</strong> WordPress sites', $value['sites'], 'mainwp' );
69 $message = sprintf( $message, $value['sites'] );
70 break;
71 case 'upgrade_all_plugins':
72 $message = $first_word . ', ' . _n( 'you just updated <strong>%d</strong> plugin', 'you just updated <strong>%d</strong> plugins', $value['items'], 'mainwp' ) . ' ' . _n( 'on <strong>%d</strong> site', 'on <strong>%d</strong> sites', $value['sites'], 'mainwp' );
73 $message = sprintf( $message, $value['items'], $value['sites'] );
74 break;
75 case 'upgrade_all_themes':
76 $message = $first_word . ', ' . _n( 'you just updated <strong>%d</strong> theme', 'you just updated <strong>%d</strong> themes', $value['items'], 'mainwp' ) . ' ' . _n( 'on <strong>%d</strong> site', 'on <strong>%d</strong> sites', $value['sites'], 'mainwp' );
77 $message = sprintf( $message, $value['items'], $value['sites'] );
78 break;
79 case 'new_post':
80 $message = $first_word . ', ' . _n( 'you just published a new post on <strong>%d</strong> site', 'you just published a new post on <strong>%d</strong> sites', $value['sites'], 'mainwp' );
81 $message = sprintf( $message, $value['sites'] );
82 break;
83 case 'new_page':
84 $message = $first_word . ', ' . _n( 'you just published a new page on <strong>%d</strong> site', 'you just published a new page on <strong>%d</strong> sites', $value['sites'], 'mainwp' );
85 $message = sprintf( $message, $value['sites'] );
86 break;
87 case 'installing_new_plugin':
88 $message = $first_word . ', ' . _n( 'you just installed a new plugin on <strong>%d</strong> site', 'you just installed a new plugin on <strong>%d</strong> sites', $value['sites'], 'mainwp' );
89 $message = sprintf( __( $message ), $value['sites'] );
90 break;
91 case 'installing_new_theme':
92 $message = $first_word . ', ' . _n( 'you just installed a new theme on <strong>%d</strong> site', 'you just installed a new theme on <strong>%d</strong> sites', $value['sites'], 'mainwp' );
93 $message = sprintf( $message, $value['sites'] );
94 break;
95 case 'create_new_user':
96 $message = $first_word . ', ' . _n( 'you just created a new user on <strong>%d</strong> site', 'you just created a new user on <strong>%d</strong> site', $value['sites'], 'mainwp' );
97 $message = sprintf( $message, $value['sites'] );
98 break;
99 }
100
101 if ( ! empty( $message ) ) {
102 $in_sec = $value['seconds'];
103 if ( $in_sec <= 60 ) {
104 if ( $what == 'upgrade_all_plugins' || $what == 'upgrade_all_themes' || $what == 'upgrade_everything' ) {
105 $real_updated = $value['real_items'];
106 $message .= ', ' . sprintf( _n( '<strong>%d</strong> total update', '<strong>%d</strong> total updates', $real_updated, 'mainwp' ), $real_updated );
107 }
108 $message .= ' ' . sprintf( _n( 'in <strong>%d</strong> second', 'in <strong>%d</strong> seconds', $in_sec, 'mainwp' ), $in_sec );
109 }
110 $message .= '!';
111 }
112
113 return $message;
114 }
115
116 public static function genTwitterButton( $content, $echo = true ) {
117 ob_start();$content
118 ?>
119 <button class="ui mini twitter button mainwp_tweet_this" msg="<?php echo urlencode($content); ?>">
120 <i class="twitter icon"></i>
121 <?php _e( 'Brag on Twitter', 'mainwp' ); ?>
122 </button>
123 <?php
124 $return = ob_get_clean();
125
126 if ( $echo ) {
127 echo $return;
128 } else {
129 return $return;
130 }
131 }
132
133 public static function updateTwitterInfo( $what, $countSites = 0, $countSec = 0, $coutRealItems = 0, $twId = 0, $countItems = 1 ) {
134 if ( empty( $twId ) ) {
135 return false;
136 }
137
138 $filters = self::get_filter();
139
140 if ( ! in_array( $what, $filters ) ) {
141 return false;
142 }
143
144 $clear_twit = false;
145 if ( empty($coutRealItems) || $coutRealItems == 1 ) {
146 $clear_twit = true;
147 }
148
149 $opt_name = 'mainwp_tt_message_' . $what;
150 $user_id = get_current_user_id();
151
152 if ( $clear_twit ) {
153 delete_user_option( $user_id, $opt_name );
154 } else {
155 if ( empty( $countSec ) ) $countSec = 1;
156 // store one twitt info only
157 $data = array( $twId => array( 'sites' => $countSites, 'seconds' => $countSec, 'items' => $countItems, 'real_items' => $coutRealItems ) );
158 if ( update_user_option( $user_id, $opt_name, $data ) ) {
159 return true;
160 }
161 }
162 return false;
163 }
164
165 public static function clearTwitterInfo( $what, $twId = 0 ) {
166 if ( empty( $twId ) ) {
167 return false;
168 }
169
170 $filters = self::get_filter();
171
172 if ( ! in_array( $what, $filters ) ) {
173 return false;
174 }
175
176 $opt_name = 'mainwp_tt_message_' . $what;
177
178 $data = get_user_option( $opt_name );
179
180 if ( ! is_array( $data ) ) {
181 $data = array();
182 }
183
184 if ( isset( $data[ $twId ] ) ) {
185 unset( $data[ $twId ] );
186 $user_id = get_current_user_id();
187 update_user_option( $user_id, $opt_name, $data );
188 }
189
190 return true;
191 }
192
193 public static function getTwitterNotice( $what, $twId = 0 ) {
194
195 $filters = self::get_filter();
196
197 if ( ! in_array( $what, $filters ) ) {
198 return false;
199 }
200
201 $opt_name = 'mainwp_tt_message_' . $what;
202 $twitter_messages = get_user_option( $opt_name );
203
204 $return = array();
205
206 if ( is_array( $twitter_messages ) ) {
207 if ( ! empty( $twId ) ) {
208 if ( isset( $twitter_messages[ $twId ] ) ) {
209 $value = $twitter_messages[ $twId ];
210 $mess = self::getNotice( $what, $value );
211 if ( ! empty( $mess ) ) {
212 $return[ $twId ] = $mess;
213 }
214 }
215 } else {
216 foreach ( $twitter_messages as $time => $value ) {
217 $mess = self::getNotice( $what, $value );
218 if ( ! empty( $mess ) ) {
219 $return[ $time ] = $mess;
220 }
221 }
222 }
223 }
224
225 return $return;
226 }
227
228 public static function getTwitToSend( $what, $twId = 0 ) {
229
230 $filters = self::get_filter();
231
232 if ( ! in_array( $what, $filters ) ) {
233 return '';
234 }
235 //@MyMainWP I just quickly updated 3 plugins on 3 #WordPress sites, 5 total updates in 12 seconds
236 $opt_name = 'mainwp_tt_message_' . $what;
237 $twitter_messages = get_user_option( $opt_name );
238 if ( is_array( $twitter_messages[ $twId ] ) && isset( $twitter_messages[ $twId ] ) ) {
239 $value = $twitter_messages[ $twId ];
240 if ( is_array( $value ) && ! empty( $value['sites'] ) && ! empty( $value['seconds'] ) ) {
241 $twit = '';
242 switch ( $what ) {
243 case 'upgrade_everything':
244 $twit = _n( 'Thanks to @MyMainWP I just quickly updated %d #WordPress site', 'Thanks to @MyMainWP I just quickly updated %d #WordPress sites', $value['sites'], 'mainwp' );
245 $twit = sprintf( $twit, $value['sites'] );
246 break;
247 case 'upgrade_all_wp_core':
248 $twit = _n( 'Thanks to @MyMainWP I just quickly updated %d #WordPress site', 'Thanks to @MyMainWP I just quickly updated %d #WordPress sites', $value['sites'], 'mainwp' );
249 $twit = sprintf( $twit, $value['sites'] );
250 break;
251 case 'upgrade_all_plugins':
252 $twit = _n( 'Thanks to @MyMainWP I just quickly updated %d plugin', 'Thanks to @MyMainWP I just quickly updated %d plugins', $value['items'], 'mainwp' ) . ' ' . _n( 'on %d #WordPress site', 'on %d #WordPress sites', $value['sites'], 'mainwp' );
253 $twit = sprintf( $twit, $value['items'], $value['sites'] );
254 break;
255 case 'upgrade_all_themes':
256 $twit = _n( 'Thanks to @MyMainWP I just quickly updated %d theme', 'Thanks to @MyMainWP I just quickly updated %d themes', $value['items'], 'mainwp' ) . ' ' . _n('on %d #WordPress site', 'on %d #WordPress sites', $value['sites'], 'mainwp' );
257 $twit = sprintf( $twit, $value['items'], $value['sites'] );
258 break;
259 case 'new_post':
260 $twit = _n( 'Thanks to @MyMainWP I just quickly published a new post on %d #WordPress site', 'Thanks to @MyMainWP I just quickly published a new post on %d #WordPress sites', $value['sites'], 'mainwp' );
261 $twit = sprintf( $twit, $value['sites'] );
262 break;
263 case 'new_page':
264 $twit = _n( 'Thanks to @MyMainWP I just quickly published a new page on %d #WordPress site', 'Thanks to @MyMainWP I just quickly published a new page on %d #WordPress sites', $value['sites'], 'mainwp' );
265 $twit = sprintf( $twit, $value['sites'] );
266 break;
267 case 'installing_new_plugin':
268 $twit = _n( 'Thanks to @MyMainWP I just quickly installed a new plugin on %d #WordPress site', 'Thanks to @MyMainWP I just quickly installed a new plugin on %d #WordPress sites', $value['sites'], 'mainwp' );
269 $twit = sprintf( $twit, $value['sites'] );
270 break;
271 case 'installing_new_theme':
272 $twit = _n( 'Thanks to @MyMainWP I just quickly installed a new theme on %d #WordPress site', 'Thanks to @MyMainWP I just quickly installed a new theme on %d #WordPress sites', $value['sites'], 'mainwp' );
273 $twit = sprintf( $twit, $value['sites'] );
274 break;
275 case 'create_new_user':
276 $twit = _n( 'Thanks to @MyMainWP I just quickly created a new user on %d #WordPress site', 'Thanks to @MyMainWP I just quickly created a new user on %d #WordPress sites', $value['sites'], 'mainwp' );
277 $twit = sprintf( $twit, $value['sites'] );
278 break;
279 }
280 if ( ! empty( $twit ) ) {
281 $in_sec = $value['seconds'];
282 if ( $in_sec <= 60 ) {
283 if ( $what == 'upgrade_all_plugins' || $what == 'upgrade_all_themes' || $what == 'upgrade_everything' ) {
284 $real_updated = $value['real_items'];
285 $twit .= ', ' . sprintf( _n( '%d total update', '%d total updates', $real_updated, 'mainwp' ), $real_updated );
286 }
287 $twit .= ' ' . sprintf( _n( 'in %d second', 'in %d seconds', $in_sec, 'mainwp' ), $in_sec );
288 }
289 $twit .= '! https://mainwp.com';
290
291 return $twit;
292 }
293 }
294 }
295
296 return '';
297 }
298 }
299