PluginProbe ʕ •ᴥ•ʔ
WP Chat App / 3.6.1
WP Chat App v3.6.1
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 2 years ago Support 2 years ago Cross.php 2 years ago Fallback.php 2 years ago Fields.php 2 years ago Helper.php 2 years ago I18n.php 2 years ago Plugin.php 2 years ago Popup.php 2 years ago PostType.php 2 years ago Review.php 2 years ago Settings.php 2 years ago Shortcode.php 2 years ago Upgrade.php 2 years ago
Cross.php
290 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 {
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 {
26 if (null == self::$instance) {
27 self::$instance = new static($pluginPrefix, $pluginInstallSearching, $pluginDirURL, $pluginFolderSlug);
28 self::$instance->doHooks();
29 }
30 return self::$instance;
31 }
32
33 public function is_plugin_exist() {
34 if ( ! function_exists( 'get_plugins' ) ) {
35 require_once ABSPATH . 'wp-admin/includes/plugin.php';
36 }
37 $all_plugins = get_plugins();
38
39 if (is_array($this->pluginFolderSlug)) {
40 foreach ($this->pluginFolderSlug as $slug) {
41 if (array_key_exists($slug, $all_plugins)) return true;
42 }
43 } else {
44 if (array_key_exists($this->pluginFolderSlug, $all_plugins)) return true;
45 }
46
47
48 return false;
49 }
50
51 public function doHooks() {
52 add_action('init', function(){
53 if (!$this->is_plugin_exist()) {
54 $notificationOption = get_option("njt_notification_{$this->pluginPrefix}_cross"); //Save the next time notification will appear
55 $popupOption = get_option("njt_popup_{$this->pluginPrefix}_cross"); //Save the next time notification will appear
56
57 if ($notificationOption === false || time() >= $notificationOption) {
58 add_action('admin_notices', array($this, 'add_notification'));
59 add_action("wp_ajax_njt_{$this->pluginPrefix}_cross_notification", array($this, 'ajax_set_notification'));
60 }
61
62 if ($popupOption === false || time() >= $popupOption) {
63 $this->showPopup = true;
64 }
65
66 add_action('wp_dashboard_setup', array($this, 'add_dashboard'));
67 add_action('admin_footer', array($this, 'add_global_script_styles'));
68 add_action("wp_ajax_njt_{$this->pluginPrefix}_cross_install", array($this, 'ajax_install_plugin'));
69 add_action("wp_ajax_njt_{$this->pluginPrefix}_cross_hide", array($this, 'ajax_hide_cross'));
70 }
71 });
72 }
73
74 public function need_update_option(){
75 $time = time() + (1 * 60 * 60 * 24); //1 day
76 update_option("njt_popup_{$this->pluginPrefix}_cross", $time);
77 update_option("njt_notification_{$this->pluginPrefix}_cross", $time);
78 }
79
80 public function add_global_script_styles()
81 {
82 if ( function_exists('current_user_can') && current_user_can('install_plugins') ) {
83 $nonce = wp_create_nonce('install-plugin_' . $this->pluginPrefix);
84 $url = self_admin_url('update.php?action=install-plugin&plugin=' . $this->pluginPrefix . '&_wpnonce=' . $nonce);
85 } else {
86 $url = admin_url("plugin-install.php?s={$this->pluginInstallSearching}&tab=search&type=term");
87 }
88
89 if ( function_exists('get_current_screen') ) {
90 $screen = get_current_screen();
91 if ( !in_array($screen->id , array('plugins', 'dashboard', 'upload')) ) return;
92 } else return;
93
94 wp_register_script("njt-popup-{$this->pluginPrefix}-cross", $this->pluginDirURL . 'assets/js/cross.js', ['jquery'], '1.0', true);
95 wp_localize_script("njt-popup-{$this->pluginPrefix}-cross", 'njtCross', array(
96 'nonce' => wp_create_nonce("njt_{$this->pluginPrefix}_cross_nonce"),
97 'media_url' => admin_url('upload.php'),
98 'filebird_install_url' => $url,
99 'show_popup' => $this->showPopup
100 ));
101 wp_enqueue_script("njt-popup-{$this->pluginPrefix}-cross");
102 ?>
103 <style>
104 @-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}
105 </style>
106 <?php
107 }
108
109 public function add_notification() {
110 if ( function_exists('get_current_screen') ) {
111 $screen = get_current_screen();
112 if ( !in_array ($screen->id, array('plugins','upload')) ) return;
113 } else return;
114
115 if ( function_exists('current_user_can') && current_user_can('install_plugins') ) {
116 $nonce = wp_create_nonce('install-plugin_' . $this->pluginPrefix);
117 $url = self_admin_url('update.php?action=install-plugin&plugin=' . $this->pluginPrefix . '&_wpnonce=' . $nonce);
118 } else {
119 $url = admin_url("plugin-install.php?s={$this->pluginInstallSearching}&tab=search&type=term");
120 }
121 ?>
122 <div class="notice notice-info is-dismissible" id="njt-ads-wrapper">
123 <div class="njt-d-row njt-justify-between">
124 <div class="njt-ads-info">
125 <h4 class="njt-ads-title"><?php _e('Recommend', 'ninjateam-whatsapp') ?></h4>
126 <p>To easily manage your files in WordPress media library with folders, please try FileBird plugin.</p>
127 <div class="njt-btn-row">
128 <a class="button button-primary" target="_blank" rel="noopener noreferrer" href="<?php echo esc_url($url) ?>">
129 <strong>I'm feeling lucky</strong>
130 </a>
131 <a class="button button-secondary" target="_blank" rel="noopener noreferrer" href="https://1.envato.market/FileBird-Premium-WP">
132 <strong>Go FileBird Pro</strong>
133 </a>
134 <a class="fbv-cross-link fbv-cross-hide-notification" href="javascript:;">
135 No, thanks
136 </a>
137 </div>
138 </div>
139 <img class="njt-ads-img" src="<?php echo NTA_WHATSAPP_PLUGIN_URL . 'assets/img/FB_Wireframe.png' ?>" alt="filebird">
140 </div>
141 </div>
142 <style>
143 .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}
144 </style>
145 <?php
146 }
147
148 public function add_dashboard(){
149 wp_add_dashboard_widget( 'dashboard_widget', 'Recommended', array($this, 'add_dashboard_widget') );
150 }
151
152 public function add_dashboard_widget(){
153 ?>
154 <style>
155 #dashboard-widgets .njt-postbox-title-wrap {
156 margin: 15px 0;
157 }
158 #dashboard-widgets .njt-postbox-title-wrap>h3 {
159 font-size: 14px;
160 font-weight: 600;
161 padding: 0;
162 margin: 0 0 10px;
163 border: 0;
164 }
165 #dashboard-widgets .njt-postbox-title-wrap>span {
166 font-size: 14px;
167 opacity: .9;
168 }
169 #dashboard-widgets .fbv-cross-window-img-wrap {
170 padding: 10px 0 20px;
171 }
172 .fbv-cross-go-pro{
173 font-weight: bold;
174 color: #2c7cb9;
175 }
176 </style>
177 <div class="njt-wrap-postbox">
178 <div class="njt-postbox-title-wrap">
179 <h3>Your WordPress media library is messy?</h3>
180 <span>Start using FileBird to organize your files into folders by drag and drop.</span>
181 </div>
182 <div class="fbv-cross-window-img-wrap">
183 <img src="https://ps.w.org/filebird/assets/screenshot-2.gif" alt="screenshot_demo">
184 </div>
185 <div class="fbv-cross-window-btn">
186 <div><a class="button button-primary fbv-cross-install" href="javascript:;"><i class="dashicons dashicons-wordpress-alt"></i>Install for free</a></div>
187 <div><a class="fbv-cross-go-pro" href="https://1.envato.market/FileBird-Pro-WP" target="_blank" rel="noopener noreferrer">Go Pro</a></div>
188 </div>
189 </div>
190 <?php
191 }
192
193 public function ajax_install_plugin(){
194 check_ajax_referer("njt_filebird_cross_nonce", 'nonce', true);
195
196 $installed = $this->pluginInstaller('filebird');
197 if ($installed === false) {
198 wp_send_json_error(array('message' => $installed));
199 }
200 try {
201 $result = activate_plugin('filebird/filebird.php');
202
203 if (is_wp_error($result)) {
204 throw new \Exception($result->get_error_message());
205 }
206 wp_send_json_success();
207 } catch (\Exception $e) {
208 throw new \Exception($e->getMessage());
209 }
210 }
211
212 public function pluginInstaller ($slug) {
213 require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
214 require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
215 require_once( ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php' );
216 require_once( ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php' );
217
218 $api = plugins_api( 'plugin_information',
219 array(
220 'slug' => $slug,
221 'fields' => array(
222 'short_description' => false,
223 'sections' => false,
224 'requires' => false,
225 'rating' => false,
226 'ratings' => false,
227 'downloaded' => false,
228 'last_updated' => false,
229 'added' => false,
230 'tags' => false,
231 'compatibility' => false,
232 'homepage' => false,
233 'donate_link' => false,
234 ),
235 )
236 );
237 $skin = new \WP_Ajax_Upgrader_Skin();
238 $upgrader = new \Plugin_Upgrader( $skin );
239 try {
240 $result = $upgrader->install( $api->download_link );
241
242 if (is_wp_error($result)) {
243 throw new \Exception($result->get_error_message());
244 }
245
246 return true;
247 } catch (\Exception $e) {
248 throw new \Exception($e->getMessage());
249 }
250
251 return false;
252 }
253
254 public function ajax_set_notification(){
255 check_ajax_referer("njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true);
256 //Save after 30 days
257 update_option("njt_notification_{$this->pluginPrefix}_cross", time() + (30 * 60 * 60 * 24));
258 wp_send_json_success();
259 }
260
261 public function ajax_hide_cross(){
262 check_ajax_referer("njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true);
263
264 $type = sanitize_text_field($_POST['type']);
265 $time = time() + (30 * 60 * 60 * 24); // hide 30 days
266
267 update_option("njt_{$type}_{$this->pluginPrefix}_cross", $time);
268 wp_send_json_success();
269 }
270 }
271 }
272
273 if ( !class_exists('FileBirdCross') ) {
274 class FileBirdCross extends NjtCross {
275 public function is_plugin_exist()
276 {
277 return (
278 defined('NJT_FILEBIRD_VERSION') ||
279 defined('NJFB_VERSION') ||
280 parent::is_plugin_exist()
281 );
282 }
283 }
284
285 FileBirdCross::get_instance('filebird', 'filebird+ninjateam', NTA_WHATSAPP_PLUGIN_URL, array('filebird/filebird.php', 'filebird-pro/filebird.php'));
286 }
287
288
289
290