Menu
4 days ago
views
3 days ago
AdminController.php
3 days ago
DashboardWidgets.php
6 months ago
PackageTemplate.php
4 years ago
AdminController.php
243 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDM\Admin; |
| 4 | |
| 5 | use WPDM\__\__; |
| 6 | use WPDM\__\Email; |
| 7 | use WPDM\__\Installer; |
| 8 | use WPDM\Admin\Menu\AddOns; |
| 9 | use WPDM\Admin\Menu\Categories; |
| 10 | use WPDM\Admin\Menu\Packages; |
| 11 | use WPDM\Admin\Menu\Settings; |
| 12 | use WPDM\Admin\Menu\Stats; |
| 13 | use WPDM\Admin\Menu\Templates; |
| 14 | use WPDM\Admin\Menu\Welcome; |
| 15 | |
| 16 | class AdminController { |
| 17 | |
| 18 | function __construct() { |
| 19 | new Welcome(); |
| 20 | new Packages(); |
| 21 | new Categories(); |
| 22 | new Templates(); |
| 23 | new AddOns(); |
| 24 | new Stats(); |
| 25 | new Settings(); |
| 26 | new DashboardWidgets(); |
| 27 | $this->actions(); |
| 28 | $this->filters(); |
| 29 | } |
| 30 | |
| 31 | function actions() { |
| 32 | add_action('init', array($this, 'registerScripts'), 1); |
| 33 | add_action('admin_enqueue_scripts', array($this, 'enqueueScripts'), 1); |
| 34 | add_action('admin_init', array($this, 'metaBoxes'), 0); |
| 35 | add_action('admin_init', array(new Email(), 'preview')); |
| 36 | add_action('admin_head', array($this, 'adminHead')); |
| 37 | add_action('admin_footer', array($this, 'adminFooter')); |
| 38 | |
| 39 | add_action("admin_notices", [$this, 'notices']); |
| 40 | add_action("wp_ajax_wpdm_remove_admin_notice", [$this, 'removeNotices']); |
| 41 | add_action("wp_ajax_hide_wpdmpro_notice", [$this, 'hideProNotice']); |
| 42 | add_action("wp_ajax_wpdm_iconFinder", [$this, 'iconFinder']); |
| 43 | |
| 44 | add_filter("user_row_actions", [$this, 'usersRowAction'], 10, 2); |
| 45 | |
| 46 | |
| 47 | } |
| 48 | |
| 49 | function filters(){ |
| 50 | add_filter("plugin_row_meta", [$this, 'pluginRowMeta'], 10, 4); |
| 51 | } |
| 52 | |
| 53 | function pluginRowMeta($plugin_meta, $plugin_file, $plugin_data, $status){ |
| 54 | if($plugin_file === 'download-manager/download-manager.php') { |
| 55 | $plugin_meta[] = "<strong><a href='https://wordpress.org/plugins/download-manager/#developers' target='_blank'>" . __("Changelog", "download-manager") . "</a></strong>"; |
| 56 | $plugin_meta[] = "<a href='https://www.wpdownloadmanager.com/docs/' target='_blank'>" . __("Docs", "download-manager") . "</a>"; |
| 57 | $plugin_meta[] = "<a href='https://www.wpdownloadmanager.com/support/' target='_blank'>" . __("Support Forum", "download-manager") . "</a>"; |
| 58 | } |
| 59 | return $plugin_meta; |
| 60 | } |
| 61 | |
| 62 | function registerScripts(){ |
| 63 | wp_register_script('wpdm-admin-js', WPDM_BASE_URL.'assets/js/wpdm.min.js', array('jquery')); |
| 64 | wp_register_style('wpdm-admin-base', WPDM_BASE_URL.'assets/adminui/css/base.css'); |
| 65 | wp_register_style('wpdm-font-awesome', WPDM_FONTAWESOME_URL); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Enqueue admin scripts & styles |
| 70 | */ |
| 71 | function enqueueScripts() { |
| 72 | |
| 73 | global $pagenow; |
| 74 | $allow_bscss = array('profile.php', 'user-edit.php', 'upload.php'); |
| 75 | $wpdm_pages = array( 'wpdm-settings', 'emails', 'wpdm-stats', 'templates', 'importable-files', 'wpdm-addons', 'orders', 'pp-license', 'wpdm-asset-manager'); |
| 76 | if (wpdm_query_var('post_type') === 'wpdmpro' || get_post_type() === 'wpdmpro' || in_array(wpdm_query_var('page'), $wpdm_pages) || ($pagenow == 'index.php' && wpdm_query_var('page') == '') || in_array($pagenow, $allow_bscss)) { |
| 77 | //wpdmdd("OK"); |
| 78 | wp_enqueue_script('jquery'); |
| 79 | wp_enqueue_script('jquery-form'); |
| 80 | wp_enqueue_script('jquery-ui-core'); |
| 81 | //wp_enqueue_script('jquery-ui-dialog'); |
| 82 | wp_enqueue_script('jquery-ui-tabs'); |
| 83 | wp_enqueue_script('jquery-ui-datepicker'); |
| 84 | wp_enqueue_script('jquery-ui-slider'); |
| 85 | wp_enqueue_script('jquery-ui-sortable'); |
| 86 | wp_enqueue_script('jquery-ui-timepicker', WPDM_BASE_URL . 'assets/js/jquery-ui-timepicker-addon.js', array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-slider')); |
| 87 | wp_enqueue_script('thickbox'); |
| 88 | wp_enqueue_style('thickbox'); |
| 89 | wp_enqueue_script('media-upload'); |
| 90 | wp_enqueue_media(); |
| 91 | |
| 92 | wp_enqueue_script('select2', WPDM_BASE_URL.'assets/select2/js/select2.min.js', array('jquery')); |
| 93 | wp_enqueue_style('select2-css', WPDM_BASE_URL.'assets/select2/css/select2.min.css'); |
| 94 | wp_enqueue_style('jqui-css', WPDM_BASE_URL.'assets/jqui/theme/jquery-ui.css'); |
| 95 | |
| 96 | wp_enqueue_script('wpdm-admin-js' ); |
| 97 | |
| 98 | if(in_array(wpdm_query_var('page'), $wpdm_pages)) |
| 99 | wp_enqueue_script('wpdm-vue', WPDM_BASE_URL.'assets/js/vue.min.js'); |
| 100 | |
| 101 | wp_enqueue_script('wpdm-admin', WPDM_BASE_URL.'assets/js/wpdm-admin.js', array('jquery')); |
| 102 | |
| 103 | |
| 104 | wp_enqueue_style( 'wpdm-font-awesome' ); |
| 105 | wp_enqueue_style( 'wpdm-admin-base' ); |
| 106 | |
| 107 | //wp_enqueue_style('wpdm-bootstrap-theme', plugins_url('/download-manager/assets/css/front.css')); |
| 108 | wp_enqueue_style('wpdm-admin-styles', WPDM_BASE_URL.'assets/css/admin-styles.css', 9999); |
| 109 | |
| 110 | wp_enqueue_style('wpdm-lock-options', WPDM_BASE_URL.'assets/css/wpdm-lock-options.css', [], WPDM_VERSION); |
| 111 | |
| 112 | wp_enqueue_style( 'wp-color-picker' ); |
| 113 | wp_enqueue_script( 'wp-color-picker' ); |
| 114 | |
| 115 | wp_enqueue_script('wpdm-modal'); |
| 116 | wp_enqueue_style('wpdm-modal'); |
| 117 | |
| 118 | |
| 119 | } |
| 120 | |
| 121 | wp_enqueue_style('wpdm-gutenberg-styles',WPDM_BASE_URL.'assets/css/gutenberg-styles.css', 9999); |
| 122 | } |
| 123 | |
| 124 | function pageHeader($title, $icon, $menus = [], $actions = [], $params = []) |
| 125 | { |
| 126 | include wpdm_admin_tpl_path("page-header.php", __DIR__.'/views'); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | function usersRowAction($actions, $user) |
| 131 | { |
| 132 | $actions[] = "<a href='edit.php?post_type=wpdmpro&page=wpdm-stats&type=history&filter=1&user_ids[0]={$user->ID}'>".__( 'Download History', 'download-manager' )."</a>"; |
| 133 | return $actions; |
| 134 | } |
| 135 | |
| 136 | function notices() |
| 137 | { |
| 138 | $class = ''; |
| 139 | if(!(int)get_option('__wpdm_hide_admin_notice', 0)) { |
| 140 | $message = '<b>Congratulation! You are using Download Manager ' . WPDM_VERSION . '</b><br/>This is a major update. You must update all Download Manager add-ons too, to keep them compatible with Download Manager ' . WPDM_VERSION; |
| 141 | printf('<div id="wpdmvnotice" class="notice notice-success is-dismissible"><p>%1$s</p></div>', $message); |
| 142 | } |
| 143 | if (is_admin() && current_user_can('manage_options') && Installer::dbUpdateRequired()) { |
| 144 | $message = sprintf(__('A database update is required for <strong>WordPress Download Manager %s</strong>. Please click the button on the right to update your database now.', WPDM_TEXT_DOMAIN), WPDM_VERSION); |
| 145 | printf('<div id="wpdmvnotice" class="notice notice-warning is-dismissible w3eden"><div style="padding: 20px;line-height: 22px;display:flex"><div style="width:9999px" >%1$s</div><div style="white-space: nowrap"><a class="btn btn-primary btn-sm" href="%2$s">Update Database</a></div></div></div>', $message, admin_url('edit.php?post_type=wpdmpro&page=wpdm-settings')); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | function removeNotices() |
| 150 | { |
| 151 | __::isAuthentic('__rnnonce', WPDM_PUB_NONCE, WPDM_ADMIN_CAP); |
| 152 | update_option('__wpdm_hide_admin_notice', 1, false); |
| 153 | wp_send_json(['success' => true]); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | function adminHead() { |
| 158 | remove_submenu_page('index.php', 'wpdm-welcome'); |
| 159 | |
| 160 | include_once wpdm_admin_tpl_path("admin-head.php"); |
| 161 | |
| 162 | } |
| 163 | |
| 164 | |
| 165 | function metaBoxes() { |
| 166 | global $ServerDirBrowser; |
| 167 | if(get_post_type(wpdm_query_var('post')) != 'wpdmpro' && wpdm_query_var('post_type') != 'wpdmpro') return; |
| 168 | |
| 169 | if(current_user_can('upload_files')) { |
| 170 | $meta_boxes = array( |
| 171 | 'wpdm-settings' => array( |
| 172 | 'title' => __( "Package Settings", "download-manager" ), |
| 173 | 'callback' => array( $this, 'packageSettings' ), |
| 174 | 'position' => 'normal', |
| 175 | 'priority' => 'low' |
| 176 | ), |
| 177 | 'wpdm-upload-file' => array( 'title' => __( "Attach File", "download-manager" ), |
| 178 | 'callback' => array( $this, 'uploadFiles' ), |
| 179 | 'position' => 'side', |
| 180 | 'priority' => 'core' |
| 181 | ), |
| 182 | 'wpdm-changelog' => array( |
| 183 | "title" => __("Changelog", WPDM_TEXT_DOMAIN), |
| 184 | "callback" => array( $this, 'changelog' ), |
| 185 | "position" => "normal", |
| 186 | "priority" => "default" |
| 187 | ), |
| 188 | ); |
| 189 | } else |
| 190 | $meta_boxes = []; |
| 191 | |
| 192 | |
| 193 | $meta_boxes = apply_filters("wpdm_meta_box", $meta_boxes); |
| 194 | foreach ($meta_boxes as $id => $meta_box) { |
| 195 | extract($meta_box); |
| 196 | if (!isset($position)) |
| 197 | $position = 'normal'; |
| 198 | if (!isset($priority)) |
| 199 | $priority = 'core'; |
| 200 | add_meta_box($id, $title, $callback, 'wpdmpro', $position, $priority); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | |
| 205 | function packageSettings($post) { |
| 206 | include wpdm_admin_tpl_path("metaboxes/package-settings.php" ); |
| 207 | } |
| 208 | |
| 209 | function uploadFiles($post) { |
| 210 | include wpdm_admin_tpl_path("metaboxes/attach-file.php" ); |
| 211 | } |
| 212 | |
| 213 | function changelog($post) |
| 214 | { |
| 215 | include wpdm_admin_tpl_path("metaboxes/changelog.php" ); |
| 216 | } |
| 217 | |
| 218 | function hideProNotice() |
| 219 | { |
| 220 | __::isAuthentic('__wpnnonce', WPDM_PUB_NONCE, WPDM_ADMIN_CAP); |
| 221 | update_option("__hide_wpdmpro_notice", strtotime('+15 days')); |
| 222 | die(); |
| 223 | } |
| 224 | |
| 225 | function adminFooter() |
| 226 | { |
| 227 | $noticeresume = (int)get_option('__hide_wpdmpro_notice'); |
| 228 | if ($noticeresume < time()) { |
| 229 | include_once wpdm_admin_tpl_path("admin-footer.php"); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | function iconFinder() { |
| 234 | //__::isAuthentic('__icononce', WPDM_PUB_NONCE, WPDM_ADMIN_CAP); |
| 235 | |
| 236 | include_once wpdm_admin_tpl_path("iconfinder.php"); |
| 237 | |
| 238 | die(); |
| 239 | |
| 240 | } |
| 241 | |
| 242 | } |
| 243 |