PluginProbe ʕ •ᴥ•ʔ
Download Manager / 3.3.63
Download Manager v3.3.63
3.3.63 3.3.62 3.3.61 3.3.60 3.3.59 3.3.58 3.3.57 3.3.56 trunk 2.1.3 2.3.0 2.5.96 2.5.97 2.6.2 2.6.96 2.8.3 2.9.99 3.0.4 3.1.05 3.1.07 3.1.08 3.1.11 3.1.12 3.1.14 3.1.17 3.1.18 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.2.04 3.2.13 3.2.14 3.2.16 3.2.18 3.2.19 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 3.2.27 3.2.28 3.2.29 3.2.30 3.2.31 3.2.32 3.2.33 3.2.34 3.2.35 3.2.37 3.2.38 3.2.39 3.2.40 3.2.41 3.2.42 3.2.43 3.2.44 3.2.45 3.2.46 3.2.47 3.2.48 3.2.49 3.2.50 3.2.51 3.2.52 3.2.53 3.2.54 3.2.55 3.2.56 3.2.57 3.2.58 3.2.59 3.2.60 3.2.61 3.2.63 3.2.64 3.2.65 3.2.66 3.2.67 3.2.68 3.2.69 3.2.70 3.2.71 3.2.72 3.2.73 3.2.74 3.2.75 3.2.76 3.2.77 3.2.78 3.2.79 3.2.80 3.2.81 3.2.82 3.2.83 3.2.84 3.2.85 3.2.86 3.2.87 3.2.88 3.2.89 3.2.90 3.2.91 3.2.92 3.2.93 3.2.94 3.2.95 3.2.96 3.2.97 3.2.98 3.2.99 3.3.00 3.3.01 3.3.02 3.3.03 3.3.04 3.3.05 3.3.06 3.3.07 3.3.08 3.3.09 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 3.3.16 3.3.17 3.3.18 3.3.19 3.3.20 3.3.21 3.3.22 3.3.23 3.3.24 3.3.25 3.3.26 3.3.27 3.3.28 3.3.29 3.3.30 3.3.31 3.3.32 3.3.33 3.3.34 3.3.35 3.3.36 3.3.37 3.3.38 3.3.39 3.3.40 3.3.41 3.3.42 3.3.43 3.3.44 3.3.45 3.3.46 3.3.47 3.3.48 3.3.49 3.3.50 3.3.51 3.3.52 3.3.53 3.3.54 3.3.55
download-manager / src / Admin / Menu / Settings.php
download-manager / src / Admin / Menu Last commit date
AddOns.php 5 years ago Categories.php 3 years ago Packages.php 1 week ago Settings.php 2 days ago Stats.php 4 years ago Templates.php 2 years ago Welcome.php 6 months ago
Settings.php
439 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 use WPDM\__\Jobs\ActivityReportJob;
10
11 define('WPDMSET_NONCE_KEY', 'xV)Op=Oa<y{Z>~jJ{Y#;(kRz<61x&[Rf$R76?[`6kyGvVa}*/.S#%1{[*>tJw2rp');
12
13 class Settings
14 {
15
16 function __construct()
17 {
18 //add_action('admin_init', array($this, 'checkSaveSettingsAuth'), 1);
19 add_action('admin_init', array($this, 'initiateSettings'));
20 add_action('wp_ajax_wpdm_settings', array($this, 'loadSettingsPage'));
21 add_action('admin_menu', array($this, 'Menu'), 999999);
22
23 add_action('wp_ajax_wpdm_delete_cron', array($this, 'deleteCron'));
24 add_action('wp_ajax_wpdm_test_recaptcha', array($this, 'testRecaptcha'));
25 add_action('wp_ajax_wpdm_send_test_activity_report', array($this, 'sendTestActivityReport'));
26 add_action('wp_ajax_wpdm_reschedule_activity_report', array($this, 'rescheduleActivityReport'));
27 }
28
29 function Menu(){
30 add_submenu_page('edit.php?post_type=wpdmpro', __( "Settings &lsaquo; Download Manager" , "download-manager" ), __( "Settings" , "download-manager" ), WPDM_ADMIN_CAP, 'wpdm-settings', array($this, 'UI'));
31 }
32
33 function checkSaveSettingsAuth(){
34 if(wpdm_query_var('task') === 'wdm_save_settings') {
35 check_ajax_referer(WPDMSET_NONCE_KEY, '__wpdms_nonce');
36 if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager'));
37 if(!current_user_can('manage_options')) die(__( "You are not allowed to change settings!", "download-manager" ));
38 }
39 }
40
41 function loadSettingsPage()
42 {
43 global $stabs;
44
45 $this->checkSaveSettingsAuth();
46
47 if (current_user_can(WPDM_MENU_ACCESS_CAP)) {
48 $section = wpdm_query_var('section');
49 if(isset($stabs[$section], $stabs[$section]['callback']))
50 call_user_func($stabs[$section]['callback']);
51 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>";
52 }
53 die();
54 }
55
56 function UI(){
57 include wpdm_admin_tpl_path("settings.php");
58 }
59
60 /**
61 * @param $tabid
62 * @param $tabtitle
63 * @param $callback
64 * @param string $icon
65 * @return array
66 */
67 public static function createMenu($tabid, $tabtitle, $callback, $icon = 'fa fa-cog')
68 {
69 return array('id' => $tabid, 'icon'=>$icon, 'link' => 'edit.php?post_type=wpdmpro&page=settings&tab=' . $tabid, 'title' => $tabtitle, 'callback' => $callback);
70 }
71
72
73 /**
74 * @usage Initiate Settings Tabs
75 */
76 function initiateSettings()
77 {
78 global $stabs;
79 $tabs = array();
80 $tabs['basic'] = array('id' => 'basic','icon'=>'fa fa-cog', 'link' => 'edit.php?post_type=wpdmpro&page=wpdm-settings', 'title' => 'Basic', 'callback' => array($this, 'basic'));
81 $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'));
82 $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'));
83
84 // Add buddypress settings menu when buddypress plugin is active
85 if (function_exists('bp_is_active')) {
86 $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'));
87 }
88
89 if(defined('WPDM_CLOUD_STORAGE')){
90 $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'));
91 }
92
93 if(!$stabs) $stabs = array();
94
95
96 $stabs = $tabs + $stabs;
97
98 $stabs = apply_filters("add_wpdm_settings_tab", $stabs);
99
100 $stabs['activity-reports'] = array('id' => 'activity-reports','icon'=>'fa fa-chart-line', 'link' => 'edit.php?post_type=wpdmpro&page=settings&tab=activity-reports', 'title' => __('Activity Reports', 'download-manager'), 'callback' => array($this, 'activityReports'));
101 $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'));
102 $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'));
103
104 }
105
106
107 /**
108 * @usage Admin Settings Tab Helper
109 * @param string $sel
110 */
111 public static function renderMenu($sel = '')
112 {
113 global $stabs;
114
115 foreach ($stabs as $tab) {
116 $isactive = ($sel == $tab['id']) ? 'class="active"' : '';
117 echo "<li {$isactive}><a id='{$tab['id']}' data-icon='{$tab['icon']}' href='{$tab['link']}'><i class='{$tab['icon']}'></i>{$tab['title']}</a></li>";
118 }
119 }
120
121 function basic(){
122
123 if (isset($_POST['task']) && $_POST['task'] == 'wdm_save_settings') {
124
125 if(!current_user_can('manage_options')) die(__( "You are not allowed to change settings!", "download-manager" ));
126
127 if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager'));
128
129 foreach ($_POST as $optn => $optv) {
130 if(strpos("__".$optn, '_wpdm_')) {
131 $optv = wpdm_sanitize_array($optv);
132 if($optn === '_wpdm_file_browser_root') {
133 $optv = realpath( get_home_path() . '/' . $optv );
134 $optv = str_replace("\\", "/", $optv);
135 if ( $optv ) {
136 $optv = trailingslashit( $optv );
137 }
138 }
139 update_option($optn, $optv, false);
140 }
141 }
142
143 WPDM()->apply->sfbAccess();
144
145 if (!isset($_POST['__wpdm_skip_locks'])) delete_option('__wpdm_skip_locks');
146 if (!isset($_POST['__wpdm_login_form'])) delete_option('__wpdm_login_form');
147 if (!isset($_POST['__wpdm_cat_desc'])) delete_option('__wpdm_cat_desc');
148 if (!isset($_POST['__wpdm_cat_img'])) delete_option('__wpdm_cat_img');
149 if (!isset($_POST['__wpdm_cat_tb'])) delete_option('__wpdm_cat_tb');
150 flush_rewrite_rules();
151 global $wp_rewrite, $WPDM;
152 $WPDM->registerPostTypeTaxonomy();
153 $wp_rewrite->flush_rules();
154 die('Settings Saved Successfully');
155 }
156 $show_db_update_notice = 0;
157 if(Installer::dbUpdateRequired()){
158 $show_db_update_notice = 1;
159 Installer::updateDB();
160 }
161
162 include wpdm_admin_tpl_path("settings/basic.php");
163
164 }
165
166 function userInterface(){
167
168 if (isset($_POST['task']) && $_POST['task'] == 'wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)) {
169
170 if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager'));
171
172 foreach ($_POST as $optn => $optv) {
173 if(strpos("__".$optn, '_wpdm_')) {
174 //$optv = wpdm_sanitize_array($optv);
175 $optv = wpdm_sanitize_array($optv, "/([^\#a-zA-Z0-9_\+\-\s:\.\;\@])/");
176 //echo $optn."=".$optv."<br/>";
177 update_option($optn, $optv, false);
178 }
179 }
180
181 die(__( "Settings Saved Successfully", "download-manager" ));
182 }
183 include wpdm_admin_tpl_path("settings/user-interface.php");
184
185 }
186
187
188 function frontEnd(){
189 if(isset($_POST['section']) && $_POST['section']=='frontend' && isset($_POST['task']) && $_POST['task']=='wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)){
190 if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager'));
191
192 foreach($_POST as $k => $v){
193 if(strpos("__".$k, '_wpdm_')){
194 $v = wpdm_sanitize_array($v);
195 update_option($k, $v, false);
196 }
197 }
198
199
200
201 global $wp_roles;
202
203 $roleids = array_keys($wp_roles->roles);
204 $roles = maybe_unserialize(get_option('__wpdm_front_end_access',array()));
205 $naroles = array_diff($roleids, $roles);
206
207 foreach($roles as $role) {
208 $role = get_role($role);
209 if(is_object($role))
210 $role->add_cap('upload_files');
211 }
212
213 foreach($naroles as $role) {
214 $role = get_role($role);
215 if(!isset($role->capabilities['edit_posts']) || $role->capabilities['edit_posts']!=1)
216 $role->remove_cap('upload_files');
217 }
218
219 $refresh = 0;
220
221 $page_id = wpdm_query_var('__wpdm_user_dashboard', 'int');
222 if($page_id != '') {
223 $page_name = get_post_field("post_name", $page_id);
224 add_rewrite_rule('^' . $page_name . '/(.+)/?', 'index.php?page_id=' . $page_id . '&udb_page=$matches[1]', 'top');
225 $refresh = 1;
226 }
227
228
229 $page_id = wpdm_query_var('__wpdm_author_profile', 'int');
230 if((int)$page_id > 0) {
231 $page_name = get_post_field("post_name", $page_id);
232 add_rewrite_rule('^' . $page_name . '/(.+)/?$', 'index.php?pagename=' . $page_name . '&profile=$matches[1]', 'top');
233 $refresh = 1;
234 }
235
236 if($refresh == 1){
237 global $wp_rewrite;
238 $wp_rewrite->flush_rules(true);
239 }
240
241 die('Settings Saved Successfully!');
242 }
243 include wpdm_admin_tpl_path("settings/frontend.php");
244 }
245
246 function socialConnects(){
247 if(isset($_POST['section']) && $_POST['section']=='social-connects' && isset($_POST['task']) && $_POST['task']=='wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)){
248
249 if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager'));
250
251 foreach($_POST as $k => $v){
252 if(strpos("__".$k, '_wpdm_')){
253 update_option($k, wpdm_sanitize_array($v), false);
254 }
255 }
256 die('Settings Saved Successfully!');
257 }
258 include wpdm_admin_tpl_path("settings/social-connects.php");
259 }
260
261 function Buddypress(){
262 if(isset($_POST['section']) && $_POST['section']=='buddypress' && isset($_POST['task']) && $_POST['task']=='wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)){
263
264 if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager'));
265
266 foreach($_POST as $k => $v){
267 if(strpos("__".$k, '_wpdm_')){
268 update_option($k, wpdm_sanitize_array($v), false);
269 }
270 }
271 die('Settings Saved Successfully!');
272 }
273 include wpdm_admin_tpl_path("settings/buddypress.php");
274 }
275
276 function cloudStorage(){
277 if(isset($_POST['section']) && $_POST['section']=='cloud-storage' && isset($_POST['task']) && $_POST['task']=='wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)){
278
279 if(!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) die(__('Security token is expired! Refresh the page and try again.', 'download-manager'));
280
281 foreach($_POST as $k => $v){
282 if(strpos("__".$k, '_wpdm_')){
283 update_option($k, wpdm_sanitize_array($v), false);
284 }
285 }
286 die('Settings Saved Successfully!');
287 }
288 include wpdm_admin_tpl_path("settings/cloud-storage.php");
289 }
290
291
292
293 function Privacy(){
294 if (wpdm_query_var('task') == 'wdm_save_settings' && wpdm_query_var('section') == 'privacy') {
295 update_option('__wpdm_noip', wpdm_query_var('__wpdm_noip', 'int', 0));
296 update_option('__wpdm_delstats_on_udel', wpdm_query_var('__wpdm_delstats_on_udel', 'int', 0));
297 update_option('__wpdm_checkout_privacy', wpdm_query_var('__wpdm_checkout_privacy', 'int', 0));
298 update_option('__wpdm_checkout_privacy_label', wpdm_query_var('__wpdm_checkout_privacy_label', 'txt'));
299 update_option('__wpdm_tmp_storage', wpdm_query_var('__wpdm_tmp_storage', 'txt', 'db'));
300 update_option('__wpdm_auto_clean_cache', wpdm_query_var('__wpdm_auto_clean_cache', 'int', 0));
301 update_option('__wpdm_cron_key', wpdm_query_var('__wpdm_cron_key', 'alphanum', ''));
302 _e("Privacy Settings Saved Successfully", "download-manager");
303 die();
304 }
305 include wpdm_admin_tpl_path("settings/privacy.php");
306 }
307
308 function cronJobs() {
309 if (wpdm_query_var('task') == 'wdm_save_settings' && wpdm_query_var('section') == 'wpdm-crons') {
310 _e("Nothing to update!", "download-manager");
311 die();
312 }
313 include wpdm_admin_tpl_path("settings/cron-jobs.php");
314 }
315
316 function deleteCron() {
317 __::isAuthentic('wpdmdcx', WPDM_PRI_NONCE, WPDM_ADMIN_CAP);
318 CronJob::delete(wpdm_query_var('cronid', 'int'));
319 wp_send_json(['success' => true]);
320 }
321
322 function testRecaptcha() {
323 if (!current_user_can(WPDM_ADMIN_CAP)) {
324 wp_send_json_error(['message' => __('Permission denied.', 'download-manager')]);
325 }
326
327 if (!wp_verify_nonce(wpdm_query_var('_wpnonce'), 'wpdm_test_recaptcha')) {
328 wp_send_json_error(['message' => __('Security token expired. Please refresh the page.', 'download-manager')]);
329 }
330
331 $token = wpdm_query_var('token', 'txt');
332 if (empty($token)) {
333 wp_send_json_error(['message' => __('No reCAPTCHA token provided.', 'download-manager')]);
334 }
335
336 $result = wpdm_recaptcha_enterprise_verify($token, 'TEST');
337
338 if ($result['success']) {
339 wp_send_json_success([
340 'message' => __('reCAPTCHA verification successful!', 'download-manager'),
341 'score' => isset($result['score']) ? $result['score'] : 'N/A'
342 ]);
343 } else {
344 wp_send_json_error([
345 'message' => isset($result['error']) ? $result['error'] : __('Verification failed.', 'download-manager'),
346 'error_code' => isset($result['error_code']) ? $result['error_code'] : '',
347 'error_details' => isset($result['error_details']) ? $result['error_details'] : ''
348 ]);
349 }
350 }
351
352 /**
353 * Activity Reports settings tab
354 */
355 function activityReports()
356 {
357 if (isset($_POST['section']) && $_POST['section'] == 'activity-reports' && isset($_POST['task']) && $_POST['task'] == 'wdm_save_settings' && current_user_can(WPDM_ADMIN_CAP)) {
358
359 if (!wp_verify_nonce($_POST['__wpdms_nonce'], WPDMSET_NONCE_KEY)) {
360 die(__('Security token is expired! Refresh the page and try again.', 'download-manager'));
361 }
362
363 // Save enabled state
364 update_option('__wpdm_activity_report_enabled', wpdm_query_var('__wpdm_activity_report_enabled', 'int', 0));
365
366 // Save schedule settings
367 update_option('__wpdm_activity_report_frequency', wpdm_query_var('__wpdm_activity_report_frequency', 'txt', 'weekly'));
368 update_option('__wpdm_activity_report_day', wpdm_query_var('__wpdm_activity_report_day', 'int', 1));
369 update_option('__wpdm_activity_report_hour', wpdm_query_var('__wpdm_activity_report_hour', 'int', 9));
370
371 // Save recipients
372 update_option('__wpdm_activity_report_admin', wpdm_query_var('__wpdm_activity_report_admin', 'int', 1));
373 $emails = wpdm_query_var('__wpdm_activity_report_emails', 'txt', '');
374 update_option('__wpdm_activity_report_emails', sanitize_text_field($emails));
375
376 // Save sections
377 $sections = isset($_POST['__wpdm_activity_report_sections']) ? array_map('sanitize_text_field', $_POST['__wpdm_activity_report_sections']) : [];
378 update_option('__wpdm_activity_report_sections', $sections);
379
380 // Reschedule the job
381 ActivityReportJob::schedule();
382
383 die(__('Activity Report Settings Saved Successfully', 'download-manager'));
384 }
385
386 include wpdm_admin_tpl_path("settings/activity-reports.php");
387 }
388
389 /**
390 * AJAX handler: Send test activity report
391 */
392 function sendTestActivityReport()
393 {
394 if (!current_user_can(WPDM_ADMIN_CAP)) {
395 wp_send_json_error(['message' => __('Permission denied.', 'download-manager')]);
396 }
397
398 if (!wp_verify_nonce(wpdm_query_var('nonce'), 'wpdm_activity_report_test')) {
399 wp_send_json_error(['message' => __('Security token expired. Please refresh the page.', 'download-manager')]);
400 }
401
402 $email = sanitize_email(wpdm_query_var('email', 'txt'));
403 if (!is_email($email)) {
404 wp_send_json_error(['message' => __('Invalid email address.', 'download-manager')]);
405 }
406
407 $result = ActivityReportJob::sendTestReport($email);
408
409 if ($result) {
410 wp_send_json_success(['message' => sprintf(__('Test report sent to %s', 'download-manager'), $email)]);
411 } else {
412 wp_send_json_error(['message' => __('Failed to send test report. Please check your email settings.', 'download-manager')]);
413 }
414 }
415
416 /**
417 * AJAX handler: Reschedule activity report job
418 */
419 function rescheduleActivityReport()
420 {
421 if (!current_user_can(WPDM_ADMIN_CAP)) {
422 wp_send_json_error(['message' => __('Permission denied.', 'download-manager')]);
423 }
424
425 if (!wp_verify_nonce(wpdm_query_var('nonce'), 'wpdm_reschedule_activity_report')) {
426 wp_send_json_error(['message' => __('Security token expired.', 'download-manager')]);
427 }
428
429 $jobId = ActivityReportJob::schedule();
430
431 if ($jobId) {
432 wp_send_json_success(['message' => __('Activity report job rescheduled.', 'download-manager'), 'job_id' => $jobId]);
433 } else {
434 wp_send_json_success(['message' => __('Activity reports are disabled or no job needed.', 'download-manager')]);
435 }
436 }
437
438 }
439