File_manager
13 hours ago
Recommended
13 hours ago
I18n.php
13 hours ago
Plugin.php
13 hours ago
cross.php
13 hours ago
functions.php
13 hours ago
index.php
13 hours ago
cross.php
300 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')) ) 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 NJT_FS_BN_PLUGIN_URL . '/assets/img/filebird.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 | if (!current_user_can('install_plugins') || !current_user_can('activate_plugins')) { |
| 197 | wp_send_json_error(array('message' => _('You do not have permission to install plugins.'))); |
| 198 | wp_die(); |
| 199 | } |
| 200 | |
| 201 | $installed = $this->pluginInstaller('filebird'); |
| 202 | if ($installed === false) { |
| 203 | wp_send_json_error(array('message' => $installed)); |
| 204 | } |
| 205 | try { |
| 206 | $result = activate_plugin('filebird/filebird.php'); |
| 207 | |
| 208 | if (is_wp_error($result)) { |
| 209 | throw new \Exception($result->get_error_message()); |
| 210 | } |
| 211 | wp_send_json_success(); |
| 212 | } catch (\Exception $e) { |
| 213 | throw new \Exception($e->getMessage()); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | public function pluginInstaller ($slug) { |
| 218 | require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
| 219 | require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
| 220 | require_once( ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php' ); |
| 221 | require_once( ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php' ); |
| 222 | |
| 223 | $api = plugins_api( 'plugin_information', |
| 224 | array( |
| 225 | 'slug' => $slug, |
| 226 | 'fields' => array( |
| 227 | 'short_description' => false, |
| 228 | 'sections' => false, |
| 229 | 'requires' => false, |
| 230 | 'rating' => false, |
| 231 | 'ratings' => false, |
| 232 | 'downloaded' => false, |
| 233 | 'last_updated' => false, |
| 234 | 'added' => false, |
| 235 | 'tags' => false, |
| 236 | 'compatibility' => false, |
| 237 | 'homepage' => false, |
| 238 | 'donate_link' => false, |
| 239 | ), |
| 240 | ) |
| 241 | ); |
| 242 | |
| 243 | if (is_wp_error($api)) { |
| 244 | throw new \Exception(_('Could not fetch plugin information.')); |
| 245 | } |
| 246 | |
| 247 | $skin = new \WP_Ajax_Upgrader_Skin(); |
| 248 | $upgrader = new \Plugin_Upgrader( $skin ); |
| 249 | try { |
| 250 | $result = $upgrader->install( $api->download_link ); |
| 251 | |
| 252 | if (is_wp_error($result)) { |
| 253 | throw new \Exception($result->get_error_message()); |
| 254 | } |
| 255 | |
| 256 | return true; |
| 257 | } catch (\Exception $e) { |
| 258 | throw new \Exception($e->getMessage()); |
| 259 | } |
| 260 | |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | public function ajax_set_notification(){ |
| 265 | check_ajax_referer("njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true); |
| 266 | //Save after 30 days |
| 267 | update_option("njt_notification_{$this->pluginPrefix}_cross", time() + (30 * 60 * 60 * 24)); |
| 268 | wp_send_json_success(); |
| 269 | } |
| 270 | |
| 271 | public function ajax_hide_cross(){ |
| 272 | check_ajax_referer("njt_{$this->pluginPrefix}_cross_nonce", 'nonce', true); |
| 273 | |
| 274 | $type = sanitize_text_field($_POST['type']); |
| 275 | $time = time() + (30 * 60 * 60 * 24); // hide 30 days |
| 276 | |
| 277 | update_option("njt_{$type}_{$this->pluginPrefix}_cross", $time); |
| 278 | wp_send_json_success(); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if ( !class_exists('FileBirdCross') ) { |
| 284 | class FileBirdCross extends NjtCross { |
| 285 | public function is_plugin_exist() |
| 286 | { |
| 287 | return ( |
| 288 | defined('NJT_FILEBIRD_VERSION') || |
| 289 | defined('NJFB_VERSION') || |
| 290 | parent::is_plugin_exist() |
| 291 | ); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | FileBirdCross::get_instance('filebird', 'filebird+ninjateam', NJT_FS_BN_PLUGIN_URL, array('filebird/filebird.php', 'filebird-pro/filebird.php')); |
| 296 | } |
| 297 | |
| 298 | |
| 299 | |
| 300 |