AddOns.php
4 years ago
Categories.php
3 years ago
Packages.php
4 days ago
Settings.php
5 months ago
Stats.php
4 years ago
Templates.php
2 years ago
Welcome.php
5 months ago
Settings.php
349 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDM\Admin\Menu; |
| 4 | |
| 5 | use WPDM\__\__; |
| 6 | use WPDM\__\CronJob; |
| 7 | use WPDM\__\Installer; |
| 8 | use WPDM\__\Session; |
| 9 | |
| 10 | define('WPDMSET_NONCE_KEY', 'xV)Op=Oa<y{Z>~jJ{Y#;(kRz<61x&[Rf$R76?[`6kyGvVa}*/.S#%1{[*>tJw2rp'); |
| 11 | |
| 12 | class Settings |
| 13 | { |
| 14 | |
| 15 | function __construct() |
| 16 | { |
| 17 | //add_action('admin_init', array($this, 'checkSaveSettingsAuth'), 1); |
| 18 | add_action('admin_init', array($this, 'initiateSettings')); |
| 19 | add_action('wp_ajax_wpdm_settings', array($this, 'loadSettingsPage')); |
| 20 | add_action('admin_menu', array($this, 'Menu'), 999999); |
| 21 | |
| 22 | add_action('wp_ajax_wpdm_delete_cron', array($this, 'deleteCron')); |
| 23 | add_action('wp_ajax_wpdm_test_recaptcha', array($this, 'testRecaptcha')); |
| 24 | } |
| 25 | |
| 26 | function Menu(){ |
| 27 | add_submenu_page('edit.php?post_type=wpdmpro', __( "Settings ‹ Download Manager" , "download-manager" ), __( "Settings" , "download-manager" ), WPDM_ADMIN_CAP, 'wpdm-settings', array($this, 'UI')); |
| 28 | } |
| 29 | |
| 30 | function checkSaveSettingsAuth(){ |
| 31 | if(wpdm_query_var('task') === 'wdm_save_settings') { |
| 32 | check_ajax_referer(WPDMSET_NONCE_KEY, '__wpdms_nonce'); |
| 33 | if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager')); |
| 34 | if(!current_user_can('manage_options')) die(__( "You are not allowed to change settings!", "download-manager" )); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | function loadSettingsPage() |
| 39 | { |
| 40 | global $stabs; |
| 41 | |
| 42 | $this->checkSaveSettingsAuth(); |
| 43 | |
| 44 | if (current_user_can(WPDM_MENU_ACCESS_CAP)) { |
| 45 | $section = wpdm_query_var('section'); |
| 46 | if(isset($stabs[$section], $stabs[$section]['callback'])) |
| 47 | call_user_func($stabs[$section]['callback']); |
| 48 | else "<div class='panel panel-danger'><div class='panel-body color-red'><i class='fa fa-exclamation-triangle'></i> ".__( "Something is wrong!", "download-manager" )."</div></div>"; |
| 49 | } |
| 50 | die(); |
| 51 | } |
| 52 | |
| 53 | function UI(){ |
| 54 | include wpdm_admin_tpl_path("settings.php"); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @param $tabid |
| 59 | * @param $tabtitle |
| 60 | * @param $callback |
| 61 | * @param string $icon |
| 62 | * @return array |
| 63 | */ |
| 64 | public static function createMenu($tabid, $tabtitle, $callback, $icon = 'fa fa-cog') |
| 65 | { |
| 66 | return array('id' => $tabid, 'icon'=>$icon, 'link' => 'edit.php?post_type=wpdmpro&page=settings&tab=' . $tabid, 'title' => $tabtitle, 'callback' => $callback); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | /** |
| 71 | * @usage Initiate Settings Tabs |
| 72 | */ |
| 73 | function initiateSettings() |
| 74 | { |
| 75 | global $stabs; |
| 76 | $tabs = array(); |
| 77 | $tabs['basic'] = array('id' => 'basic','icon'=>'fa fa-cog', 'link' => 'edit.php?post_type=wpdmpro&page=wpdm-settings', 'title' => 'Basic', 'callback' => array($this, 'basic')); |
| 78 | $tabs['wpdmui'] = array('id' => 'wpdmui','icon'=>'fas fa-fill-drip', 'link' => 'edit.php?post_type=wpdmpro&page=wpdm-settings', 'title' => 'User Interface', 'callback' => array($this, 'userInterface')); |
| 79 | $tabs['frontend'] = array('id' => 'frontend','icon'=>'fa fa-desktop', 'link' => 'edit.php?post_type=wpdmpro&page=wpdm-settings&tab=frontend', 'title' => 'Frontend Access', 'callback' => array($this, 'Frontend')); |
| 80 | |
| 81 | // Add buddypress settings menu when buddypress plugin is active |
| 82 | if (function_exists('bp_is_active')) { |
| 83 | $tabs['buddypress'] = array('id' => 'buddypress','icon'=>'fa fa-users', 'link' => 'edit.php?post_type=wpdmpro&page=wpdm-settings&tab=buddypress', 'title' => 'BuddyPress', 'callback' => array($this, 'Buddypress')); |
| 84 | } |
| 85 | |
| 86 | if(defined('WPDM_CLOUD_STORAGE')){ |
| 87 | $tabs['cloud-storage'] = array('id' => 'cloud-storage','icon'=>'fa fa-cloud-arrow-up', 'link' => 'edit.php?post_type=wpdmpro&page=wpdm-settings&tab=cloud-storage', 'title' => 'Cloud Storage', 'callback' => array($this, 'cloudStorage')); |
| 88 | } |
| 89 | |
| 90 | if(!$stabs) $stabs = array(); |
| 91 | |
| 92 | |
| 93 | $stabs = $tabs + $stabs; |
| 94 | |
| 95 | $stabs = apply_filters("add_wpdm_settings_tab", $stabs); |
| 96 | |
| 97 | $stabs['wpdm-crons'] = array('id' => 'wpdm-crons','icon'=>'fa fa-clock-rotate-left', 'link' => 'edit.php?post_type=wpdmpro&page=settings&tab=wpdm-crons', 'title' => __('Cron Jobs', 'download-manager'), 'callback' => array($this, 'cronJobs')); |
| 98 | $stabs['privacy'] = array('id' => 'privacy','icon'=>'fas fa-user-shield', 'link' => 'edit.php?post_type=wpdmpro&page=wpdm-settings&tab=privacy', 'title' => 'Privacy', 'callback' => array($this, 'privacy')); |
| 99 | |
| 100 | } |
| 101 | |
| 102 | |
| 103 | /** |
| 104 | * @usage Admin Settings Tab Helper |
| 105 | * @param string $sel |
| 106 | */ |
| 107 | public static function renderMenu($sel = '') |
| 108 | { |
| 109 | global $stabs; |
| 110 | |
| 111 | foreach ($stabs as $tab) { |
| 112 | $isactive = ($sel == $tab['id']) ? 'class="active"' : ''; |
| 113 | echo "<li {$isactive}><a id='{$tab['id']}' data-icon='{$tab['icon']}' href='{$tab['link']}'><i class='{$tab['icon']}'></i>{$tab['title']}</a></li>"; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | function basic(){ |
| 118 | |
| 119 | if (isset($_POST['task']) && $_POST['task'] == 'wdm_save_settings') { |
| 120 | |
| 121 | if(!current_user_can('manage_options')) die(__( "You are not allowed to change settings!", "download-manager" )); |
| 122 | |
| 123 | if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager')); |
| 124 | |
| 125 | foreach ($_POST as $optn => $optv) { |
| 126 | if(strpos("__".$optn, '_wpdm_')) { |
| 127 | $optv = wpdm_sanitize_array($optv); |
| 128 | if($optn === '_wpdm_file_browser_root') { |
| 129 | $optv = realpath( get_home_path() . '/' . $optv ); |
| 130 | $optv = str_replace("\\", "/", $optv); |
| 131 | if ( $optv ) { |
| 132 | $optv = trailingslashit( $optv ); |
| 133 | } |
| 134 | } |
| 135 | update_option($optn, $optv, false); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | WPDM()->apply->sfbAccess(); |
| 140 | |
| 141 | if (!isset($_POST['__wpdm_skip_locks'])) delete_option('__wpdm_skip_locks'); |
| 142 | if (!isset($_POST['__wpdm_login_form'])) delete_option('__wpdm_login_form'); |
| 143 | if (!isset($_POST['__wpdm_cat_desc'])) delete_option('__wpdm_cat_desc'); |
| 144 | if (!isset($_POST['__wpdm_cat_img'])) delete_option('__wpdm_cat_img'); |
| 145 | if (!isset($_POST['__wpdm_cat_tb'])) delete_option('__wpdm_cat_tb'); |
| 146 | flush_rewrite_rules(); |
| 147 | global $wp_rewrite, $WPDM; |
| 148 | $WPDM->registerPostTypeTaxonomy(); |
| 149 | $wp_rewrite->flush_rules(); |
| 150 | die('Settings Saved Successfully'); |
| 151 | } |
| 152 | $show_db_update_notice = 0; |
| 153 | if(Installer::dbUpdateRequired()){ |
| 154 | $show_db_update_notice = 1; |
| 155 | Installer::updateDB(); |
| 156 | } |
| 157 | |
| 158 | include wpdm_admin_tpl_path("settings/basic.php"); |
| 159 | |
| 160 | } |
| 161 | |
| 162 | function userInterface(){ |
| 163 | |
| 164 | if (isset($_POST['task']) && $_POST['task'] == 'wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)) { |
| 165 | |
| 166 | if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager')); |
| 167 | |
| 168 | foreach ($_POST as $optn => $optv) { |
| 169 | if(strpos("__".$optn, '_wpdm_')) { |
| 170 | //$optv = wpdm_sanitize_array($optv); |
| 171 | $optv = wpdm_sanitize_array($optv, "/([^\#a-zA-Z0-9_\+\-\s:\.\;\@])/"); |
| 172 | //echo $optn."=".$optv."<br/>"; |
| 173 | update_option($optn, $optv, false); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | die(__( "Settings Saved Successfully", "download-manager" )); |
| 178 | } |
| 179 | include wpdm_admin_tpl_path("settings/user-interface.php"); |
| 180 | |
| 181 | } |
| 182 | |
| 183 | |
| 184 | function frontEnd(){ |
| 185 | if(isset($_POST['section']) && $_POST['section']=='frontend' && isset($_POST['task']) && $_POST['task']=='wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)){ |
| 186 | if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager')); |
| 187 | |
| 188 | foreach($_POST as $k => $v){ |
| 189 | if(strpos("__".$k, '_wpdm_')){ |
| 190 | $v = wpdm_sanitize_array($v); |
| 191 | update_option($k, $v, false); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | |
| 196 | |
| 197 | global $wp_roles; |
| 198 | |
| 199 | $roleids = array_keys($wp_roles->roles); |
| 200 | $roles = maybe_unserialize(get_option('__wpdm_front_end_access',array())); |
| 201 | $naroles = array_diff($roleids, $roles); |
| 202 | |
| 203 | foreach($roles as $role) { |
| 204 | $role = get_role($role); |
| 205 | if(is_object($role)) |
| 206 | $role->add_cap('upload_files'); |
| 207 | } |
| 208 | |
| 209 | foreach($naroles as $role) { |
| 210 | $role = get_role($role); |
| 211 | if(!isset($role->capabilities['edit_posts']) || $role->capabilities['edit_posts']!=1) |
| 212 | $role->remove_cap('upload_files'); |
| 213 | } |
| 214 | |
| 215 | $refresh = 0; |
| 216 | |
| 217 | $page_id = wpdm_query_var('__wpdm_user_dashboard', 'int'); |
| 218 | if($page_id != '') { |
| 219 | $page_name = get_post_field("post_name", $page_id); |
| 220 | add_rewrite_rule('^' . $page_name . '/(.+)/?', 'index.php?page_id=' . $page_id . '&udb_page=$matches[1]', 'top'); |
| 221 | $refresh = 1; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | $page_id = wpdm_query_var('__wpdm_author_profile', 'int'); |
| 226 | if((int)$page_id > 0) { |
| 227 | $page_name = get_post_field("post_name", $page_id); |
| 228 | add_rewrite_rule('^' . $page_name . '/(.+)/?$', 'index.php?pagename=' . $page_name . '&profile=$matches[1]', 'top'); |
| 229 | $refresh = 1; |
| 230 | } |
| 231 | |
| 232 | if($refresh == 1){ |
| 233 | global $wp_rewrite; |
| 234 | $wp_rewrite->flush_rules(true); |
| 235 | } |
| 236 | |
| 237 | die('Settings Saved Successfully!'); |
| 238 | } |
| 239 | include wpdm_admin_tpl_path("settings/frontend.php"); |
| 240 | } |
| 241 | |
| 242 | function socialConnects(){ |
| 243 | if(isset($_POST['section']) && $_POST['section']=='social-connects' && isset($_POST['task']) && $_POST['task']=='wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)){ |
| 244 | |
| 245 | if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager')); |
| 246 | |
| 247 | foreach($_POST as $k => $v){ |
| 248 | if(strpos("__".$k, '_wpdm_')){ |
| 249 | update_option($k, wpdm_sanitize_array($v), false); |
| 250 | } |
| 251 | } |
| 252 | die('Settings Saved Successfully!'); |
| 253 | } |
| 254 | include wpdm_admin_tpl_path("settings/social-connects.php"); |
| 255 | } |
| 256 | |
| 257 | function Buddypress(){ |
| 258 | if(isset($_POST['section']) && $_POST['section']=='buddypress' && isset($_POST['task']) && $_POST['task']=='wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)){ |
| 259 | |
| 260 | if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager')); |
| 261 | |
| 262 | foreach($_POST as $k => $v){ |
| 263 | if(strpos("__".$k, '_wpdm_')){ |
| 264 | update_option($k, wpdm_sanitize_array($v), false); |
| 265 | } |
| 266 | } |
| 267 | die('Settings Saved Successfully!'); |
| 268 | } |
| 269 | include wpdm_admin_tpl_path("settings/buddypress.php"); |
| 270 | } |
| 271 | |
| 272 | function cloudStorage(){ |
| 273 | if(isset($_POST['section']) && $_POST['section']=='cloud-storage' && isset($_POST['task']) && $_POST['task']=='wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)){ |
| 274 | |
| 275 | if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager')); |
| 276 | |
| 277 | foreach($_POST as $k => $v){ |
| 278 | if(strpos("__".$k, '_wpdm_')){ |
| 279 | update_option($k, wpdm_sanitize_array($v), false); |
| 280 | } |
| 281 | } |
| 282 | die('Settings Saved Successfully!'); |
| 283 | } |
| 284 | include wpdm_admin_tpl_path("settings/cloud-storage.php"); |
| 285 | } |
| 286 | |
| 287 | |
| 288 | |
| 289 | function Privacy(){ |
| 290 | if (wpdm_query_var('task') == 'wdm_save_settings' && wpdm_query_var('section') == 'privacy') { |
| 291 | update_option('__wpdm_noip', wpdm_query_var('__wpdm_noip', 'int', 0)); |
| 292 | update_option('__wpdm_delstats_on_udel', wpdm_query_var('__wpdm_delstats_on_udel', 'int', 0)); |
| 293 | update_option('__wpdm_checkout_privacy', wpdm_query_var('__wpdm_checkout_privacy', 'int', 0)); |
| 294 | update_option('__wpdm_checkout_privacy_label', wpdm_query_var('__wpdm_checkout_privacy_label', 'txt')); |
| 295 | update_option('__wpdm_tmp_storage', wpdm_query_var('__wpdm_tmp_storage', 'txt', 'db')); |
| 296 | update_option('__wpdm_auto_clean_cache', wpdm_query_var('__wpdm_auto_clean_cache', 'int', 0)); |
| 297 | update_option('__wpdm_cron_key', wpdm_query_var('__wpdm_cron_key', 'alphanum', '')); |
| 298 | _e("Privacy Settings Saved Successfully", "download-manager"); |
| 299 | die(); |
| 300 | } |
| 301 | include wpdm_admin_tpl_path("settings/privacy.php"); |
| 302 | } |
| 303 | |
| 304 | function cronJobs() { |
| 305 | if (wpdm_query_var('task') == 'wdm_save_settings' && wpdm_query_var('section') == 'wpdm-crons') { |
| 306 | _e("Nothing to update!", "download-manager"); |
| 307 | die(); |
| 308 | } |
| 309 | include wpdm_admin_tpl_path("settings/crons.php"); |
| 310 | } |
| 311 | |
| 312 | function deleteCron() { |
| 313 | __::isAuthentic('wpdmdcx', WPDM_PRI_NONCE, WPDM_ADMIN_CAP); |
| 314 | CronJob::delete(wpdm_query_var('cronid', 'int')); |
| 315 | wp_send_json(['success' => true]); |
| 316 | } |
| 317 | |
| 318 | function testRecaptcha() { |
| 319 | if (!current_user_can(WPDM_ADMIN_CAP)) { |
| 320 | wp_send_json_error(['message' => __('Permission denied.', 'download-manager')]); |
| 321 | } |
| 322 | |
| 323 | if (!wp_verify_nonce(wpdm_query_var('_wpnonce'), 'wpdm_test_recaptcha')) { |
| 324 | wp_send_json_error(['message' => __('Security token expired. Please refresh the page.', 'download-manager')]); |
| 325 | } |
| 326 | |
| 327 | $token = wpdm_query_var('token', 'txt'); |
| 328 | if (empty($token)) { |
| 329 | wp_send_json_error(['message' => __('No reCAPTCHA token provided.', 'download-manager')]); |
| 330 | } |
| 331 | |
| 332 | $result = wpdm_recaptcha_enterprise_verify($token, 'TEST'); |
| 333 | |
| 334 | if ($result['success']) { |
| 335 | wp_send_json_success([ |
| 336 | 'message' => __('reCAPTCHA verification successful!', 'download-manager'), |
| 337 | 'score' => isset($result['score']) ? $result['score'] : 'N/A' |
| 338 | ]); |
| 339 | } else { |
| 340 | wp_send_json_error([ |
| 341 | 'message' => isset($result['error']) ? $result['error'] : __('Verification failed.', 'download-manager'), |
| 342 | 'error_code' => isset($result['error_code']) ? $result['error_code'] : '', |
| 343 | 'error_details' => isset($result['error_details']) ? $result['error_details'] : '' |
| 344 | ]); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | } |
| 349 |