PluginProbe ʕ •ᴥ•ʔ
WP Chat App / 3.8.2
WP Chat App v3.8.2
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
Support 2 months ago Cross.php 2 months ago Fallback.php 2 months ago Fields.php 2 months ago Helper.php 2 months ago I18n.php 2 months ago Plugin.php 2 months ago Popup.php 2 months ago PostType.php 2 months ago Review.php 2 months ago Settings.php 2 months ago Shortcode.php 2 months ago Upgrade.php 2 months ago
Cross.php
491 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 public $showSidebar = false;
14
15 protected static $instance = null;
16
17 public function __construct( $pluginPrefix, $pluginInstallSearching, $pluginDirURL, $pluginFolderSlug ) {
18 $this->pluginPrefix = $pluginPrefix;
19 $this->pluginInstallSearching = $pluginInstallSearching;
20 $this->pluginDirURL = $pluginDirURL;
21 $this->pluginFolderSlug = $pluginFolderSlug;
22 }
23
24 public static function get_instance( $pluginPrefix, $pluginInstallSearching, $pluginDirURL, $pluginFolderSlug ) {
25 if ( null === self::$instance ) {
26 self::$instance = new static( $pluginPrefix, $pluginInstallSearching, $pluginDirURL, $pluginFolderSlug );
27 self::$instance->doHooks();
28 }
29 return self::$instance;
30 }
31
32 public function is_plugin_exist() {
33 if ( ! function_exists( 'get_plugins' ) ) {
34 require_once ABSPATH . 'wp-admin/includes/plugin.php';
35 }
36 $all_plugins = get_plugins();
37
38 if ( is_array( $this->pluginFolderSlug ) ) {
39 foreach ( $this->pluginFolderSlug as $slug ) {
40 if ( array_key_exists( $slug, $all_plugins ) ) {
41 return true;
42 }
43 }
44 } elseif ( array_key_exists( $this->pluginFolderSlug, $all_plugins ) ) {
45 return true;
46 }
47
48 return false;
49 }
50
51 private function get_sidebar_screens() {
52 $screens = array( 'upload', 'edit-post', 'edit-page' );
53 if ( class_exists( 'WooCommerce' ) ) {
54 $screens[] = 'edit-product';
55 }
56 return $screens;
57 }
58
59 public function doHooks() {
60 add_action(
61 'init',
62 function () {
63 if ( ! $this->is_plugin_exist() ) {
64 $notificationOption = get_option( "njt_notification_{$this->pluginPrefix}_cross" ); //Save the next time notification will appear
65 $popupOption = get_option( "njt_popup_{$this->pluginPrefix}_cross" ); //Save the next time notification will appear
66 $sidebarOption = get_option( "njt_sidebar_{$this->pluginPrefix}_cross" ); //Save the next time notification will appear
67 if ( false === $notificationOption || time() >= $notificationOption ) {
68 add_action( 'admin_notices', array( $this, 'add_notification' ) );
69 add_action( "wp_ajax_njt_{$this->pluginPrefix}_cross_notification", array( $this, 'ajax_set_notification' ) );
70 }
71
72 if ( false === $popupOption || time() >= $popupOption ) {
73 $this->showPopup = true;
74 }
75
76 if ( false === $sidebarOption || time() >= $sidebarOption ) {
77 $this->showSidebar = true;
78 }
79
80 add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard' ) );
81 add_action( 'admin_footer', array( $this, 'add_global_script_styles' ) );
82 add_action( 'admin_footer', array( $this, 'add_media_sidebar_html' ) );
83 add_action( "wp_ajax_njt_{$this->pluginPrefix}_cross_install", array( $this, 'ajax_install_plugin' ) );
84 add_action( "wp_ajax_njt_{$this->pluginPrefix}_cross_hide", array( $this, 'ajax_hide_cross' ) );
85 }
86 }
87 );
88 }
89
90 public function need_update_option() {
91 $time = 5 * 60;
92 update_option( "njt_popup_{$this->pluginPrefix}_cross", $time );
93 update_option( "njt_notification_{$this->pluginPrefix}_cross", $time );
94 }
95
96 public function add_global_script_styles() {
97 if ( function_exists( 'current_user_can' ) && current_user_can( 'install_plugins' ) ) {
98 $nonce = wp_create_nonce( 'install-plugin_' . $this->pluginPrefix );
99 $url = self_admin_url( 'update.php?action=install-plugin&plugin=' . $this->pluginPrefix . '&_wpnonce=' . $nonce );
100 } else {
101 $url = admin_url( "plugin-install.php?s={$this->pluginInstallSearching}&tab=search&type=term" );
102 }
103
104 if ( function_exists( 'get_current_screen' ) ) {
105 $screen = get_current_screen();
106 if ( ! in_array( $screen->id, array_merge( array( 'plugins', 'dashboard' ), $this->get_sidebar_screens() ) ) ) {
107 return;
108 }
109 } else {
110 return;
111 }
112
113 wp_register_script( "njt-popup-{$this->pluginPrefix}-cross", $this->pluginDirURL . 'assets/js/cross.js', array( 'jquery' ), '1.0', true );
114 wp_localize_script(
115 "njt-popup-{$this->pluginPrefix}-cross",
116 'njtCross',
117 array(
118 'nonce' => wp_create_nonce( "njt_{$this->pluginPrefix}_cross_nonce" ),
119 'media_url' => admin_url( 'upload.php' ),
120 'filebird_install_url' => $url,
121 'show_popup' => $this->showPopup,
122 )
123 );
124 wp_enqueue_script( "njt-popup-{$this->pluginPrefix}-cross" );
125 ?>
126 <style>
127 @-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}
128 /* Media library sidebar */
129 #wpbody.njt-fb-has-sidebar{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch}
130 #wpbody #wpbody-content .wrap.njt-fb-has-sidebar{display:-webkit-box;display:-ms-flexbox;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch}
131 #wpbody.njt-fb-has-sidebar>.wrap{-webkit-box-flex:1;-ms-flex:1;flex:1;min-width:0}
132 #wpbody.njt-fb-has-sidebar #wpbody-content, #wpbody-content .wrap.njt-fb-has-sidebar .products-content{padding-left:16px}
133 #njt-fb-media-sidebar{position:relative;padding: 16px 16px 0 0;width:240px;min-width:240px;-ms-flex-negative:0;flex-shrink:0;border-right:1px solid #dcdcde;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}
134 #njt-fb-media-sidebar .njt-fb-preview-img{-ms-flex-negative:0;flex-shrink:0}
135 #njt-fb-media-sidebar .njt-fb-preview-img img{width:100%;display:block}
136 #njt-fb-media-sidebar .njt-fb-promo-body{padding:16px 0 20px;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;gap:12px}
137 #njt-fb-media-sidebar .njt-fb-promo-brand{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:7px;background:#fff;border:1px solid #e8e8e8;border-radius:6px;padding:4px 8px 4px 4px;-webkit-box-shadow:0px 1px 2px 0px #0000000D;box-shadow:0px 1px 2px 0px #0000000D;font-size:12px;font-weight:600;color:#122940;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content}
138 #njt-fb-media-sidebar .njt-fb-promo-brand span{ line-height: 1; }
139 #njt-fb-media-sidebar .njt-fb-promo-copy{font-size:14px;font-weight:600;line-height:1.45;color:#122940;margin:0}
140 #njt-fb-media-sidebar .njt-fb-install-btn {text-align: center;font-size: 13px;font-weight: 600;}
141 #njt-fb-media-sidebar .fbv-cross-install { width: 100%;text-align: center;}
142 #njt-fb-media-sidebar .fbv-cross-install .dashicons, #njt-ads-wrapper .fbv-cross-install .dashicons{display: none;}
143 #njt-fb-media-sidebar .njt-fb-close-btn{position:absolute;top:20px;right:20px;width:20px;height:18px;border:none;border-radius:4px;background:#fff;color:#1d2427;font-size:15px;line-height:1;cursor:pointer;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;padding:0 0 1px;z-index:2;-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px);-webkit-box-shadow:0 1px 5px rgba(0,0,0,.2);box-shadow:0 1px 5px rgba(0,0,0,.2);-webkit-transition:background .15s,border-color .15s;-o-transition:background .15s,border-color .15s;transition:background .15s,border-color .15s}
144 #njt-fb-media-sidebar .njt-fb-close-btn:hover{background:#00000080;color: #fff;}
145 #njt-fb-confirm-modal{position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.4);z-index:100001}
146 .njt-fb-confirm-dialog{background:#fff;border-radius:8px;padding:20px;width:280px;position:absolute;-webkit-box-shadow:0 4px 20px rgba(0,0,0,.18);box-shadow:0 4px 20px rgba(0,0,0,.18)}
147 .njt-fb-confirm-dialog::before{content:'';position:absolute;left:-9px;top:16px;border-top:9px solid transparent;border-bottom:9px solid transparent;border-right:9px solid rgba(0,0,0,.1)}
148 .njt-fb-confirm-dialog::after{content:'';position:absolute;left:-8px;top:17px;border-top:8px solid transparent;border-bottom:8px solid transparent;border-right:8px solid #fff}
149 .njt-fb-confirm-x{position:absolute;top:10px;right:12px;background:none;border:none;font-size:22px;cursor:pointer;color:#666;line-height:1;padding:0;width:28px;height:28px;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center}
150 .njt-fb-confirm-x:hover{color:#000}
151 .njt-fb-confirm-dialog h3{font-size:16px;font-weight:600;margin:0 0 8px;color:#1d2427}
152 .njt-fb-confirm-dialog>p{margin:0 0 14px;color:#444;font-size:14px;line-height:1.5}
153 .njt-fb-confirm-check{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:8px;margin-bottom:18px;font-size:14px;cursor:pointer;color:#1d2327}
154 .njt-fb-confirm-check input{margin:0;cursor:pointer}
155 .njt-fb-confirm-actions{display:-webkit-box;display:-ms-flexbox;display:flex;justify-content: flex-end;gap:8px;background:#F7F8F9;margin:16px -20px -20px;padding:14px 20px;border-radius:0 0 8px 8px}
156 </style>
157 <?php
158 }
159
160 public function add_notification() {
161 if ( function_exists( 'get_current_screen' ) ) {
162 $screen = get_current_screen();
163 if ( ! in_array( $screen->id, array( 'plugins', 'upload' ) ) ) {
164 return;
165 }
166 } else {
167 return;
168 }
169
170 if ( function_exists( 'current_user_can' ) && current_user_can( 'install_plugins' ) ) {
171 $nonce = wp_create_nonce( 'install-plugin_' . $this->pluginPrefix );
172 $url = self_admin_url( 'update.php?action=install-plugin&plugin=' . $this->pluginPrefix . '&_wpnonce=' . $nonce );
173 } else {
174 $url = admin_url( "plugin-install.php?s={$this->pluginInstallSearching}&tab=search&type=term" );
175 }
176 ?>
177 <div class="notice notice-info is-dismissible" id="njt-ads-wrapper">
178 <div class="njt-d-row njt-justify-between">
179 <div class="njt-ads-info">
180 <h4 class="njt-ads-title"><?php echo esc_html__( 'Recommend', 'wp-whatsapp' ); ?></h4>
181 <p>To easily manage your files in WordPress media library with folders, please try FileBird plugin.</p>
182 <div class="njt-btn-row">
183 <a class="button button-primary fbv-cross-install njt-ads-install-button" target="_blank" rel="noopener noreferrer" href="javascript:;">
184 <strong>Free install</strong>
185 </a>
186 <a class="button button-secondary" target="_blank" rel="noopener noreferrer" href="https://1.envato.market/FileBird-Premium-WP">
187 <strong>Go FileBird Pro</strong>
188 </a>
189 <a class="fbv-cross-link fbv-cross-hide-notification" href="javascript:;">
190 No, thanks
191 </a>
192 </div>
193 </div>
194 <img class="njt-ads-img" src="<?php echo esc_url( NTA_WHATSAPP_PLUGIN_URL . 'assets/img/FB_Wireframe.png' ); ?>" alt="filebird">
195 </div>
196 </div>
197 <style>
198 .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}
199 </style>
200 <?php
201 }
202
203 public function add_dashboard() {
204 wp_add_dashboard_widget( 'dashboard_widget', 'Recommended', array( $this, 'add_dashboard_widget' ) );
205 }
206
207 public function add_dashboard_widget() {
208 ?>
209 <style>
210 #dashboard-widgets .njt-postbox-title-wrap {
211 margin: 15px 0;
212 }
213 #dashboard-widgets .njt-postbox-title-wrap>h3 {
214 font-size: 14px;
215 font-weight: 600;
216 padding: 0;
217 margin: 0 0 10px;
218 border: 0;
219 }
220 #dashboard-widgets .njt-postbox-title-wrap>span {
221 font-size: 14px;
222 opacity: .9;
223 }
224 #dashboard-widgets .fbv-cross-window-img-wrap {
225 padding: 10px 0 20px;
226 }
227 .fbv-cross-go-pro{
228 font-weight: bold;
229 color: #2c7cb9;
230 }
231 </style>
232 <div class="njt-wrap-postbox">
233 <div class="njt-postbox-title-wrap">
234 <h3>Your WordPress media library is messy?</h3>
235 <span>Start using FileBird to organize your files into folders by drag and drop.</span>
236 </div>
237 <div class="fbv-cross-window-img-wrap">
238 <img src="https://ps.w.org/filebird/assets/screenshot-2.gif" alt="screenshot_demo">
239 </div>
240 <div class="fbv-cross-window-btn">
241 <div><a class="button button-primary fbv-cross-install" href="javascript:;"><i class="dashicons dashicons-wordpress-alt"></i>Install for free</a></div>
242 <div><a class="fbv-cross-go-pro" href="https://1.envato.market/FileBird-Pro-WP" target="_blank" rel="noopener noreferrer">Go Pro</a></div>
243 </div>
244 </div>
245 <?php
246 }
247
248 public function add_media_sidebar_html() {
249 if ( ! function_exists( 'get_current_screen' ) ) {
250 return;
251 }
252 $screen = get_current_screen();
253 if ( ! $screen || ! in_array( $screen->id, $this->get_sidebar_screens() ) ) {
254 return;
255 }
256 if ( ! $this->showSidebar ) {
257 return;
258 }
259
260 $nonce = wp_create_nonce( "njt_{$this->pluginPrefix}_cross_nonce" );
261 $media_url = admin_url( 'upload.php' );
262 $action = esc_js( "njt_{$this->pluginPrefix}_cross_install" );
263 switch ( $screen->id ) {
264 case 'upload':
265 $img_url = esc_js( NTA_WHATSAPP_PLUGIN_URL . 'assets/img/fb-media-sidebar.jpg' );
266 $promo_text = __( 'Your media files is messy? Organize into folders with ease.', 'wp-whatsapp' );
267 break;
268 case 'edit-post':
269 case 'edit-page':
270 $img_url = esc_js( NTA_WHATSAPP_PLUGIN_URL . 'assets/img/fb-post-sidebar.jpg' );
271 $promo_text = __( 'Organize your posts into folders with ease.', 'wp-whatsapp' );
272 break;
273 case 'edit-product':
274 $img_url = esc_js( NTA_WHATSAPP_PLUGIN_URL . 'assets/img/fb-products-sidebar.jpg' );
275 $promo_text = __( 'Organize your products into folders effortlessly.', 'wp-whatsapp' );
276 break;
277 default:
278 $img_url = esc_js( NTA_WHATSAPP_PLUGIN_URL . 'assets/img/fb-media-sidebar.jpg' );
279 $promo_text = __( 'Your media files is messy? Organize into folders with ease.', 'wp-whatsapp' );
280 break;
281 }
282 $icon_url = esc_js( NTA_WHATSAPP_PLUGIN_URL . 'assets/img/fb-icon.png' );
283 ?>
284 <script>
285 (function($) {
286 $(function() {
287 if ($('#njt-fb-media-sidebar').length) return;
288 var nonce = '<?php echo esc_js( $nonce ); ?>';
289 var mediaUrl = '<?php echo esc_js( $media_url ); ?>';
290 var action = '<?php echo $action; ?>';
291 var loading = '<i class="dashicons dashicons-update-alt"></i>Installing...';
292 var done = '<i class="dashicons dashicons-saved"></i>Installed! Organize files now';
293 var err = '<i class="dashicons dashicons-warning"></i>Install failed. Retry';
294
295 var sidebar = $(
296 '<div id="njt-fb-media-sidebar">' +
297 '<button class="njt-fb-close-btn" title="Close" aria-label="Close">&times;</button>' +
298 '<div class="njt-fb-preview-img">' +
299 '<img src="<?php echo $img_url; ?>" alt="FileBird">' +
300 '</div>' +
301 '<div class="njt-fb-promo-body">' +
302 '<div class="njt-fb-promo-brand">' +
303 '<img src="<?php echo $icon_url; ?>" alt="" width="14" height="14">' +
304 '<span>FileBird</span>' +
305 '</div>' +
306 '<p class="njt-fb-promo-copy"><?php echo esc_js( $promo_text ); ?></p>' +
307 '<div><a class="button button-primary fbv-cross-install" href="javascript:;"><i class="dashicons dashicons-wordpress-alt"></i><?php echo esc_js( __( 'Install for free', 'wp-whatsapp' ) ); ?></a></div>' +
308 '</div>' +
309 '</div>'
310 );
311 <?php if ( in_array( $screen->id, array( 'edit-product' ) ) ) : ?>
312 const wrap = $('#wpbody #wpbody-content .wrap');
313 // get all element in wrap and wrap them into a div
314 const all_elements = wrap.children();
315 const wrap_div = $('<div class="products-content">');
316 all_elements.appendTo(wrap_div);
317 wrap.addClass('njt-fb-has-sidebar').append(sidebar);
318 wrap.append(wrap_div);
319 <?php else : ?>
320 $('#wpbody').addClass('njt-fb-has-sidebar').prepend(sidebar);
321 <?php endif; ?>
322
323 function njtFbRemoveSidebar() {
324 sidebar.remove();
325 <?php if ( in_array( $screen->id, array( 'edit-product' ) ) ) : ?>
326 var wrap = $('#wpbody #wpbody-content .wrap');
327 wrap.removeClass('njt-fb-has-sidebar');
328 wrap.find('.products-content').children().appendTo(wrap);
329 wrap.find('.products-content').remove();
330 <?php else : ?>
331 $('#wpbody').removeClass('njt-fb-has-sidebar');
332 <?php endif; ?>
333 }
334
335 sidebar.find('.njt-fb-close-btn').on('click', function() {
336 var modal = $(
337 '<div id="njt-fb-confirm-modal">' +
338 '<div class="njt-fb-confirm-dialog">' +
339 '<h3>Remove this widget?</h3>' +
340 '<label class="njt-fb-confirm-check">' +
341 '<input type="checkbox" id="njt-fb-dont-show">' +
342 " Don\'t display this widget again" +
343 '</label>' +
344 '<div class="njt-fb-confirm-actions">' +
345 '<button class="button button-primary njt-fb-confirm-submit">Remove</button>' +
346 '<button class="button njt-fb-confirm-cancel">Cancel</button>' +
347 '</div>' +
348 '</div>' +
349 '</div>'
350 );
351 $('body').append(modal);
352 var rect = sidebar[0].getBoundingClientRect();
353 modal.find('.njt-fb-confirm-dialog').css({ top: rect.top +3, left: rect.right -2 });
354 modal.on('click', function(e) {
355 if (!$(e.target).closest('.njt-fb-confirm-dialog').length) {
356 modal.remove();
357 }
358 });
359 modal.find('.njt-fb-confirm-cancel, .njt-fb-confirm-x').on('click', function() {
360 modal.remove();
361 });
362 modal.find('.njt-fb-confirm-submit').on('click', function() {
363 var dontShow = modal.find('#njt-fb-dont-show').is(':checked');
364 modal.remove();
365 njtFbRemoveSidebar();
366 if (dontShow) {
367 $.post(ajaxurl, { action: 'njt_filebird_cross_hide', nonce: nonce, type: 'sidebar', dont_show_again: true });
368 } else {
369 $.post(ajaxurl, { action: 'njt_filebird_cross_hide', nonce: nonce, type: 'sidebar' });
370 }
371 });
372 });
373
374 sidebar.find('.njt-fb-install-btn').on('click', function(e) {
375 e.preventDefault();
376 var btn = $(this);
377 if (btn.hasClass('njt-fb-installing') || btn.hasClass('njt-fb-done')) return;
378 $.ajax({
379 url: ajaxurl, method: 'POST',
380 data: { action: action, nonce: nonce },
381 beforeSend: function() { btn.addClass('njt-fb-installing').html(loading); },
382 success: function(res) {
383 if (res.success) {
384 btn.removeClass('njt-fb-installing').addClass('njt-fb-done').html(done);
385 btn.off('click').on('click', function() { window.location.href = mediaUrl; });
386 } else {
387 btn.removeClass('njt-fb-installing').addClass('njt-fb-error').html(err);
388 }
389 },
390 error: function() { btn.removeClass('njt-fb-installing').addClass('njt-fb-error').html(err); }
391 });
392 });
393 });
394 })(jQuery);
395 </script>
396 <?php
397 }
398
399 public function ajax_install_plugin() {
400 if ( ! function_exists( 'current_user_can' ) || ! current_user_can( 'install_plugins' ) ) {
401 wp_send_json_error( array( 'message' => 'Current user cannot install this plugin' ) );
402 }
403
404 check_ajax_referer( 'njt_filebird_cross_nonce', 'nonce', true );
405
406 $installed = $this->pluginInstaller( 'filebird' );
407 if ( false === $installed ) {
408 wp_send_json_error( array( 'message' => $installed ) );
409 }
410 try {
411 $result = activate_plugin( 'filebird/filebird.php' );
412
413 if ( is_wp_error( $result ) ) {
414 throw new \Exception( $result->get_error_message() );
415 }
416 wp_send_json_success();
417 } catch ( \Exception $e ) {
418 throw new \Exception( esc_html( $e->getMessage() ) );
419 }
420 }
421
422 public function pluginInstaller( $slug ) {
423 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
424 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
425 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
426 require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
427
428 $api = plugins_api(
429 'plugin_information',
430 array(
431 'slug' => $slug,
432 'fields' => array(
433 'short_description' => false,
434 'sections' => false,
435 'requires' => false,
436 'rating' => false,
437 'ratings' => false,
438 'downloaded' => false,
439 'last_updated' => false,
440 'added' => false,
441 'tags' => false,
442 'compatibility' => false,
443 'homepage' => false,
444 'donate_link' => false,
445 ),
446 )
447 );
448 $skin = new \WP_Ajax_Upgrader_Skin();
449 $upgrader = new \Plugin_Upgrader( $skin );
450 try {
451 $result = $upgrader->install( $api->download_link );
452
453 if ( is_wp_error( $result ) ) {
454 throw new \Exception( esc_html( $result->get_error_message() ) );
455 }
456
457 return true;
458 } catch ( \Exception $e ) {
459 throw new \Exception( esc_html( $e->getMessage() ) );
460 }
461
462 return false;
463 }
464
465 public function ajax_set_notification() {
466 check_ajax_referer( "njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true );
467 //Save after 30 days
468 update_option( "njt_notification_{$this->pluginPrefix}_cross", time() + ( 30 * 60 * 60 * 24 ) );
469 wp_send_json_success();
470 }
471
472 public function ajax_hide_cross() {
473 check_ajax_referer( "njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true );
474
475 $type = sanitize_text_field( $_POST['type'] );
476 $dont_show_again = isset( $_POST['dont_show_again'] ) ? sanitize_text_field( $_POST['dont_show_again'] ) : false;
477 if(!$dont_show_again) {
478 $time = time() + ( 30 * 60 * 60 * 24 ); // hide 30 days
479 } else {
480 $time = time() + ( 10000 * 60 * 60 * 24 ); // hide 10000 days
481 }
482
483 update_option( "njt_{$type}_{$this->pluginPrefix}_cross", $time );
484 wp_send_json_success();
485 }
486 }
487 }
488
489
490
491