PluginProbe ʕ •ᴥ•ʔ
WP Chat App / 3.6.9
WP Chat App v3.6.9
3.8.1 3.8.2 trunk 2.6 3.4 3.4.1 3.4.2 3.4.4 3.4.5 3.4.6 3.5 3.6 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0
wp-whatsapp / includes / Cross.php
wp-whatsapp / includes Last commit date
Recommended 1 year ago Support 1 year ago Cross.php 1 year ago Fallback.php 1 year ago Fields.php 1 year ago Helper.php 1 year ago I18n.php 1 year ago Plugin.php 1 year ago Popup.php 1 year ago PostType.php 1 year ago Review.php 1 year ago Settings.php 1 year ago Shortcode.php 1 year ago Upgrade.php 1 year ago
Cross.php
307 lines
1 <?php
2 defined( 'ABSPATH' ) || exit;
3
4 if ( ! class_exists( 'NjtCross' ) ) {
5 class NjtCross {
6
7 public $pluginPrefix = '';
8 public $pluginInstallSearching = '';
9 public $pluginDirURL = '';
10 public $pluginFolderSlug = '';
11
12 public $showPopup = false;
13
14 protected static $instance = null;
15
16 public function __construct( $pluginPrefix, $pluginInstallSearching, $pluginDirURL, $pluginFolderSlug ) {
17 $this->pluginPrefix = $pluginPrefix;
18 $this->pluginInstallSearching = $pluginInstallSearching;
19 $this->pluginDirURL = $pluginDirURL;
20 $this->pluginFolderSlug = $pluginFolderSlug;
21 }
22
23 public static function get_instance( $pluginPrefix, $pluginInstallSearching, $pluginDirURL, $pluginFolderSlug ) {
24 if ( null === self::$instance ) {
25 self::$instance = new static( $pluginPrefix, $pluginInstallSearching, $pluginDirURL, $pluginFolderSlug );
26 self::$instance->doHooks();
27 }
28 return self::$instance;
29 }
30
31 public function is_plugin_exist() {
32 if ( ! function_exists( 'get_plugins' ) ) {
33 require_once ABSPATH . 'wp-admin/includes/plugin.php';
34 }
35 $all_plugins = get_plugins();
36
37 if ( is_array( $this->pluginFolderSlug ) ) {
38 foreach ( $this->pluginFolderSlug as $slug ) {
39 if ( array_key_exists( $slug, $all_plugins ) ) {
40 return true;
41 }
42 }
43 } elseif ( array_key_exists( $this->pluginFolderSlug, $all_plugins ) ) {
44 return true;
45 }
46
47 return false;
48 }
49
50 public function doHooks() {
51 add_action(
52 'init',
53 function () {
54 if ( ! $this->is_plugin_exist() ) {
55 $notificationOption = get_option( "njt_notification_{$this->pluginPrefix}_cross" ); //Save the next time notification will appear
56 $popupOption = get_option( "njt_popup_{$this->pluginPrefix}_cross" ); //Save the next time notification will appear
57
58 if ( $notificationOption === false || time() >= $notificationOption ) {
59 add_action( 'admin_notices', array( $this, 'add_notification' ) );
60 add_action( "wp_ajax_njt_{$this->pluginPrefix}_cross_notification", array( $this, 'ajax_set_notification' ) );
61 }
62
63 if ( $popupOption === false || time() >= $popupOption ) {
64 $this->showPopup = true;
65 }
66
67 add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard' ) );
68 add_action( 'admin_footer', array( $this, 'add_global_script_styles' ) );
69 add_action( "wp_ajax_njt_{$this->pluginPrefix}_cross_install", array( $this, 'ajax_install_plugin' ) );
70 add_action( "wp_ajax_njt_{$this->pluginPrefix}_cross_hide", array( $this, 'ajax_hide_cross' ) );
71 }
72 }
73 );
74 }
75
76 public function need_update_option() {
77 $time = time() + ( 1 * 60 * 60 * 24 ); //1 day
78 update_option( "njt_popup_{$this->pluginPrefix}_cross", $time );
79 update_option( "njt_notification_{$this->pluginPrefix}_cross", $time );
80 }
81
82 public function add_global_script_styles() {
83 if ( function_exists( 'current_user_can' ) && current_user_can( 'install_plugins' ) ) {
84 $nonce = wp_create_nonce( 'install-plugin_' . $this->pluginPrefix );
85 $url = self_admin_url( 'update.php?action=install-plugin&plugin=' . $this->pluginPrefix . '&_wpnonce=' . $nonce );
86 } else {
87 $url = admin_url( "plugin-install.php?s={$this->pluginInstallSearching}&tab=search&type=term" );
88 }
89
90 if ( function_exists( 'get_current_screen' ) ) {
91 $screen = get_current_screen();
92 if ( ! in_array( $screen->id, array( 'plugins', 'dashboard', 'upload' ) ) ) {
93 return;
94 }
95 } else {
96 return;
97 }
98
99 wp_register_script( "njt-popup-{$this->pluginPrefix}-cross", $this->pluginDirURL . 'assets/js/cross.js', array( 'jquery' ), '1.0', true );
100 wp_localize_script(
101 "njt-popup-{$this->pluginPrefix}-cross",
102 'njtCross',
103 array(
104 'nonce' => wp_create_nonce( "njt_{$this->pluginPrefix}_cross_nonce" ),
105 'media_url' => admin_url( 'upload.php' ),
106 'filebird_install_url' => $url,
107 'show_popup' => $this->showPopup,
108 )
109 );
110 wp_enqueue_script( "njt-popup-{$this->pluginPrefix}-cross" );
111 ?>
112 <style>
113 @-webkit-keyframes rotate360{to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@keyframes rotate360{to{-webkit-transform:rotate(1turn);transform:rotate(1turn)}}@-webkit-keyframes dotLoad{0%{opacity:1}to{opacity:.1}}@keyframes dotLoad{0%{opacity:1}to{opacity:.1}}.fbv-icon{background-color:transparent;background-position:50%;background-repeat:no-repeat;background-size:contain;display:inline-block;height:1em;width:1em}.fbv-i-folder{background-image:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23fff' d='M10 4H4c-1.11 0-2 .89-2 2v12a2 2 0 002 2h16a2 2 0 002-2V8a2 2 0 00-2-2h-8l-2-2z'/%3E%3C/svg%3E")}.fbv-cross-wrap{bottom:45px;position:fixed;right:30px;-webkit-transition:all .4s ease;-o-transition:all .4s ease;transition:all .4s ease;-webkit-transition-delay:.5s;-o-transition-delay:.5s;transition-delay:.5s;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:100000}.fbv-cross-wrap.fbv_permanent_hide{opacity:0;pointer-events:none}.fbv-cross-link{color:#a1a1a1;font-size:12px;text-decoration:none}.fbv-cross-link:active,.fbv-cross-link:focus,.fbv-cross-link:hover{-webkit-box-shadow:none;box-shadow:none;color:#a1a1a1;opacity:.8;outline:none}.fbv-cross-popup{cursor:pointer;position:relative;z-index:100}.fbv-cross-icon-wrap{background-color:#0085ba;-webkit-box-shadow:0 6px 10px 2px rgba(0,0,0,.1);box-shadow:0 6px 10px 2px rgba(0,0,0,.1);line-height:1;position:relative;height:56px;width:56px;border-radius:56px}.fbv-cross-icon-wrap i{color:#fff;font-size:32px;left:50%;margin-left:-16px;margin-top:-16px;position:absolute;top:50%;-webkit-transition:all .4s ease;-o-transition:all .4s ease;transition:all .4s ease}.fbv-cross-popup-open .fbv-cross-icon-wrap i.fbv-icon{opacity:0;-webkit-transform:rotate(1turn);-ms-transform:rotate(1turn);transform:rotate(1turn)}.fbv-cross-icon-wrap i.dashicons{opacity:0;-webkit-transform:rotate(0);-ms-transform:rotate(0);transform:rotate(0);height:auto;width:auto}.fbv-cross-popup-open .fbv-cross-icon-wrap i.dashicons{opacity:1;-webkit-transform:rotate(1turn);-ms-transform:rotate(1turn);transform:rotate(1turn)}.fbv-cross-sub{background-color:#fff;border-radius:3px;-webkit-box-shadow:0 2px 10px 0 rgba(0,0,0,.1);box-shadow:0 2px 10px 0 rgba(0,0,0,.1);color:#0085ba;font-size:14px;font-weight:500;margin:-13px 10px 0 0;padding:4px 12px;position:absolute;right:100%;top:50%;-webkit-transition:all .4s ease;-o-transition:all .4s ease;transition:all .4s ease;white-space:nowrap}.fbv-cross-popup-open .fbv-cross-sub{opacity:0;pointer-events:none;-webkit-transform:translateY(15px);-ms-transform:translateY(15px);transform:translateY(15px);visibility:hidden}.fbv-cross-window{background-color:#fff;border-radius:3px;bottom:100%;-webkit-box-shadow:0 10px 10px 4px rgba(0,0,0,.04);box-shadow:0 10px 10px 4px rgba(0,0,0,.04);margin-bottom:15px;opacity:0;pointer-events:none;position:absolute;right:-5px;-webkit-transform:translateY(50px);-ms-transform:translateY(50px);transform:translateY(50px);-webkit-transition:all .4s ease;-o-transition:all .4s ease;transition:all .4s ease;visibility:hidden;width:360px;z-index:99}.fbv-cross-window-mess{background-color:#0085ba;border-radius:3px 3px 0 0;color:#fff;padding:15px 20px}.fbv-cross-window-mess h3{color:#fff;font-size:14px;margin:0 0 10px}.fbv-cross-window-mess span{font-size:14px;line-height:1.5;opacity:.9}.fbv-cross-window-img-wrap{padding:20px}.fbv-cross-window-img-wrap img{max-width:100%}.fbv-cross-window-btn{padding:5px 20px 25px;text-align:center}.fbv-cross-window-btn .button-primary{-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;font-weight:500;height:42px;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;margin-bottom:10px;max-width:100%;min-width:162px;padding:0 20px}.fbv-cross-window-btn .button-primary,.fbv-cross-window-btn .button-primary:active,.fbv-cross-window-btn .button-primary:focus,.fbv-cross-window-btn .button-primary:hover{-webkit-box-shadow:none;box-shadow:none;outline:none}.fbv-cross-window-btn .button-primary i{margin-right:8px}.fbv-cross-window-btn .button-primary .dashicons-saved{background-color:#fff;color:#0085ba;font-size:18px;height:18px;width:18px;border-radius:18px}.fbv-cross-window-btn .button-primary.fbv_installing,.fbv-cross-window-btn .button-primary.fbv_installing:active,.fbv-cross-window-btn .button-primary.fbv_installing:focus,.fbv-cross-window-btn .button-primary.fbv_installing:hover{background-color:#e4f7ff;border-color:#e4f7ff;color:#0085ba;cursor:not-allowed}.fbv-cross-window-btn .button-primary.fbv_installing i{-webkit-animation:rotate360 1s linear infinite both;animation:rotate360 1s linear infinite both}.fbv-cross-popup-open .fbv-cross-window{opacity:1;pointer-events:all;-webkit-transform:translateY(0);-ms-transform:translateY(0);transform:translateY(0);visibility:visible}.fbv-noti-install-failed{margin-bottom:10px;margin-top:5px}.fbv-noti-install-failed a{font-weight:600}.fbv-label-error{color:#e90808;margin-bottom:2px}.text-dots:after,.text-dots:before{content:"."}.text-dots:after,.text-dots:before,.text-dots span{-webkit-animation:dotLoad 1s linear 1s infinite alternate;animation:dotLoad 1s linear 1s infinite alternate;opacity:.1}.text-dots:before{-webkit-animation-delay:.5s;animation-delay:.5s}.text-dots:after{-webkit-animation-delay:1.5s;animation-delay:1.5s}
114 </style>
115 <?php
116 }
117
118 public function add_notification() {
119 if ( function_exists( 'get_current_screen' ) ) {
120 $screen = get_current_screen();
121 if ( ! in_array( $screen->id, array( 'plugins', 'upload' ) ) ) {
122 return;
123 }
124 } else {
125 return;
126 }
127
128 if ( function_exists( 'current_user_can' ) && current_user_can( 'install_plugins' ) ) {
129 $nonce = wp_create_nonce( 'install-plugin_' . $this->pluginPrefix );
130 $url = self_admin_url( 'update.php?action=install-plugin&plugin=' . $this->pluginPrefix . '&_wpnonce=' . $nonce );
131 } else {
132 $url = admin_url( "plugin-install.php?s={$this->pluginInstallSearching}&tab=search&type=term" );
133 }
134 ?>
135 <div class="notice notice-info is-dismissible" id="njt-ads-wrapper">
136 <div class="njt-d-row njt-justify-between">
137 <div class="njt-ads-info">
138 <h4 class="njt-ads-title"><?php _e( 'Recommend', 'wp-whatsapp' ); ?></h4>
139 <p>To easily manage your files in WordPress media library with folders, please try FileBird plugin.</p>
140 <div class="njt-btn-row">
141 <a class="button button-primary" target="_blank" rel="noopener noreferrer" href="<?php echo esc_url( $url ); ?>">
142 <strong>I'm feeling lucky</strong>
143 </a>
144 <a class="button button-secondary" target="_blank" rel="noopener noreferrer" href="https://1.envato.market/FileBird-Premium-WP">
145 <strong>Go FileBird Pro</strong>
146 </a>
147 <a class="fbv-cross-link fbv-cross-hide-notification" href="javascript:;">
148 No, thanks
149 </a>
150 </div>
151 </div>
152 <img class="njt-ads-img" src="<?php echo NTA_WHATSAPP_PLUGIN_URL . 'assets/img/FB_Wireframe.png'; ?>" alt="filebird">
153 </div>
154 </div>
155 <style>
156 .njt-d-row{-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-ms-flexbox;display:flex}.njt-justify-between{-webkit-box-pack:justify;-ms-flex-pack:justify;justify-content:space-between}.njt-ads-info{padding:15px 0 30px}@media screen and (max-width:782px){.njt-ads-info{padding:0}}.njt-ads-info p{margin-bottom:25px}.njt-ads-title{font-size:16px;margin:0 0 15px}.njt-ads-img{max-width:252px}.njt-btn-row{line-height:30px}.njt-btn-row>.button{margin-right:10px}
157 </style>
158 <?php
159 }
160
161 public function add_dashboard() {
162 wp_add_dashboard_widget( 'dashboard_widget', 'Recommended', array( $this, 'add_dashboard_widget' ) );
163 }
164
165 public function add_dashboard_widget() {
166 ?>
167 <style>
168 #dashboard-widgets .njt-postbox-title-wrap {
169 margin: 15px 0;
170 }
171 #dashboard-widgets .njt-postbox-title-wrap>h3 {
172 font-size: 14px;
173 font-weight: 600;
174 padding: 0;
175 margin: 0 0 10px;
176 border: 0;
177 }
178 #dashboard-widgets .njt-postbox-title-wrap>span {
179 font-size: 14px;
180 opacity: .9;
181 }
182 #dashboard-widgets .fbv-cross-window-img-wrap {
183 padding: 10px 0 20px;
184 }
185 .fbv-cross-go-pro{
186 font-weight: bold;
187 color: #2c7cb9;
188 }
189 </style>
190 <div class="njt-wrap-postbox">
191 <div class="njt-postbox-title-wrap">
192 <h3>Your WordPress media library is messy?</h3>
193 <span>Start using FileBird to organize your files into folders by drag and drop.</span>
194 </div>
195 <div class="fbv-cross-window-img-wrap">
196 <img src="https://ps.w.org/filebird/assets/screenshot-2.gif" alt="screenshot_demo">
197 </div>
198 <div class="fbv-cross-window-btn">
199 <div><a class="button button-primary fbv-cross-install" href="javascript:;"><i class="dashicons dashicons-wordpress-alt"></i>Install for free</a></div>
200 <div><a class="fbv-cross-go-pro" href="https://1.envato.market/FileBird-Pro-WP" target="_blank" rel="noopener noreferrer">Go Pro</a></div>
201 </div>
202 </div>
203 <?php
204 }
205
206 public function ajax_install_plugin() {
207 if ( ! function_exists( 'current_user_can' ) || ! current_user_can( 'install_plugins' ) ) {
208 wp_send_json_error( array( 'message' => 'Current user cannot install this plugin' ) );
209 }
210
211 check_ajax_referer( 'njt_filebird_cross_nonce', 'nonce', true );
212
213 $installed = $this->pluginInstaller( 'filebird' );
214 if ( $installed === false ) {
215 wp_send_json_error( array( 'message' => $installed ) );
216 }
217 try {
218 $result = activate_plugin( 'filebird/filebird.php' );
219
220 if ( is_wp_error( $result ) ) {
221 throw new \Exception( $result->get_error_message() );
222 }
223 wp_send_json_success();
224 } catch ( \Exception $e ) {
225 throw new \Exception( $e->getMessage() );
226 }
227 }
228
229 public function pluginInstaller( $slug ) {
230 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
231 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
232 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
233 require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
234
235 $api = plugins_api(
236 'plugin_information',
237 array(
238 'slug' => $slug,
239 'fields' => array(
240 'short_description' => false,
241 'sections' => false,
242 'requires' => false,
243 'rating' => false,
244 'ratings' => false,
245 'downloaded' => false,
246 'last_updated' => false,
247 'added' => false,
248 'tags' => false,
249 'compatibility' => false,
250 'homepage' => false,
251 'donate_link' => false,
252 ),
253 )
254 );
255 $skin = new \WP_Ajax_Upgrader_Skin();
256 $upgrader = new \Plugin_Upgrader( $skin );
257 try {
258 $result = $upgrader->install( $api->download_link );
259
260 if ( is_wp_error( $result ) ) {
261 throw new \Exception( $result->get_error_message() );
262 }
263
264 return true;
265 } catch ( \Exception $e ) {
266 throw new \Exception( $e->getMessage() );
267 }
268
269 return false;
270 }
271
272 public function ajax_set_notification() {
273 check_ajax_referer( "njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true );
274 //Save after 30 days
275 update_option( "njt_notification_{$this->pluginPrefix}_cross", time() + ( 30 * 60 * 60 * 24 ) );
276 wp_send_json_success();
277 }
278
279 public function ajax_hide_cross() {
280 check_ajax_referer( "njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true );
281
282 $type = sanitize_text_field( $_POST['type'] );
283 $time = time() + ( 30 * 60 * 60 * 24 ); // hide 30 days
284
285 update_option( "njt_{$type}_{$this->pluginPrefix}_cross", $time );
286 wp_send_json_success();
287 }
288 }
289 }
290
291 if ( ! class_exists( 'FileBirdCross' ) ) {
292 class FileBirdCross extends NjtCross {
293 public function is_plugin_exist() {
294 return (
295 defined( 'NJT_FILEBIRD_VERSION' ) ||
296 defined( 'NJFB_VERSION' ) ||
297 parent::is_plugin_exist()
298 );
299 }
300 }
301
302 FileBirdCross::get_instance( 'filebird', 'filebird+ninjateam', NTA_WHATSAPP_PLUGIN_URL, array( 'filebird/filebird.php', 'filebird-pro/filebird.php' ) );
303 }
304
305
306
307