| 1 |
<?php |
| 2 |
|
| 3 |
defined('ABSPATH') or die("Cannot access pages directly."); |
| 4 |
|
| 5 |
use Melograno\UsageTracker\Collectors\Plugin\WpDataTablesCollector; |
| 6 |
use Melograno\UsageTracker\Core\UsageTracker; |
| 7 |
|
| 8 |
/** |
| 9 |
* Created by PhpStorm. |
| 10 |
* User: miljkomilosevic |
| 11 |
* Date: 12/2/16 |
| 12 |
* Time: 4:12 PM |
| 13 |
*/ |
| 14 |
class WDTSettingsController { |
| 15 |
|
| 16 |
public static function sanitizeSettings( $settings ){ |
| 17 |
foreach( $settings as $key=>&$setting ){ |
| 18 |
if( is_array( $setting )){ |
| 19 |
foreach( $setting as &$childSetting ){ |
| 20 |
$childSetting = sanitize_text_field( $childSetting ); |
| 21 |
} |
| 22 |
} elseif (function_exists('sanitize_textarea_field') && ($key === "wdtCustomJs" || $key === "wdtCustomCss")) { |
| 23 |
if ($key === "wdtCustomJs" && ! current_user_can( 'unfiltered_html' ) ) { |
| 24 |
$setting = ''; |
| 25 |
} else { |
| 26 |
$setting = sanitize_textarea_field($setting); |
| 27 |
} |
| 28 |
} elseif ($key === 'wdtInterfaceLanguage') { |
| 29 |
// Security Fix: Prevent Path Traversal / LFI for language file (CVE-2026-28039) |
| 30 |
if (!empty($setting)) { |
| 31 |
// Only allow basename (no directory traversal) |
| 32 |
$setting = basename(sanitize_text_field($setting)); |
| 33 |
|
| 34 |
// Verify it's a valid language file |
| 35 |
if (substr($setting, -8) !== '.inc.php') { |
| 36 |
$setting = ''; // Invalid format, reject it |
| 37 |
} else { |
| 38 |
// Double-check the file exists in the lang directory |
| 39 |
$langPath = WDT_ROOT_PATH . 'source/lang/' . $setting; |
| 40 |
if (!file_exists($langPath) || !is_file($langPath)) { |
| 41 |
$setting = ''; // File doesn't exist, reject it |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
} else{ |
| 46 |
$setting = sanitize_text_field( $setting ); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
return $settings; |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
public static function saveSettings( $settings ){ |
| 55 |
$settings = self::sanitizeSettings( stripslashes_deep( $settings ) ); |
| 56 |
$autoUpdateOption = (int)$settings['wdtAutoUpdateOption']; |
| 57 |
|
| 58 |
if (!$autoUpdateOption){ |
| 59 |
global $wpdb; |
| 60 |
$wpdb->query( |
| 61 |
$wpdb->prepare( |
| 62 |
"UPDATE " . $wpdb->prefix . "wpdatatables_cache |
| 63 |
SET auto_update = %d", |
| 64 |
$autoUpdateOption |
| 65 |
) |
| 66 |
); |
| 67 |
$wpdb->query( |
| 68 |
$wpdb->prepare( |
| 69 |
"UPDATE " . $wpdb->prefix . "wpdatatables |
| 70 |
SET auto_update_cache = %d", |
| 71 |
$autoUpdateOption |
| 72 |
) |
| 73 |
); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
foreach($settings as $key=>$value) { |
| 78 |
update_option($key, $value); |
| 79 |
} |
| 80 |
|
| 81 |
do_action('wpdatatables_after_save_settings'); |
| 82 |
} |
| 83 |
|
| 84 |
public static function getCurrentPluginConfig() { |
| 85 |
$settings = array( |
| 86 |
|
| 87 |
'wdtSiteLink' => get_option('wdtSiteLink'), |
| 88 |
|
| 89 |
'wdtInterfaceLanguage' => get_option('wdtInterfaceLanguage'), |
| 90 |
'wdtTablesPerPage' => get_option('wdtTablesPerPage'), |
| 91 |
'wdtDateFormat' => get_option('wdtDateFormat'), |
| 92 |
'wdtTimeFormat' => get_option('wdtTimeFormat'), |
| 93 |
'wdtBaseSkin' => get_option('wdtBaseSkin'), |
| 94 |
'wdtNumberFormat' => get_option('wdtNumberFormat'), |
| 95 |
'wdtRenderFilter' => get_option('wdtRenderFilter'), |
| 96 |
'wdtDecimalPlaces' => get_option('wdtDecimalPlaces'), |
| 97 |
'wdtCSVDelimiter' => get_option('wdtCSVDelimiter'), |
| 98 |
'wdtSortingOrderBrowseTables'=> get_option('wdtSortingOrderBrowseTables'), |
| 99 |
'wdtTabletWidth' => get_option('wdtTabletWidth'), |
| 100 |
'wdtMobileWidth' => get_option('wdtMobileWidth'), |
| 101 |
'wdtPurchaseCode' => get_option('wdtPurchaseCode'), |
| 102 |
'wdtGettingStartedPageStatus'=> get_option('wdtGettingStartedPageStatus'), |
| 103 |
'wdtIncludeBootstrap' => get_option('wdtIncludeBootstrap'), |
| 104 |
'wdtIncludeBootstrapBackEnd'=> get_option('wdtIncludeBootstrapBackEnd'), |
| 105 |
'wdtPreventDeletingTables' => get_option('wdtPreventDeletingTables'), |
| 106 |
'wdtParseShortcodes' => get_option('wdtParseShortcodes'), |
| 107 |
'wdtNumbersAlign' => get_option('wdtNumbersAlign'), |
| 108 |
'wdtBorderRemoval' => get_option('wdtBorderRemoval'), |
| 109 |
'wdtBorderRemovalHeader' => get_option('wdtBorderRemovalHeader'), |
| 110 |
'wdtUseSeparateCon' => get_option('wdtUseSeparateCon'), |
| 111 |
'wdtMySQLHost' => get_option('wdtMySqlHost'), |
| 112 |
'wdtMySqlDB' => get_option('wdtMySqlDB'), |
| 113 |
'wdtMySqlUser' => get_option('wdtMySqlUser'), |
| 114 |
'wdtMySqlPwd' => get_option('wdtMySqlPwd'), |
| 115 |
'wdtMySqlPort' => get_option('wdtMySqlPort'), |
| 116 |
'wdtCustomCss' => get_option('wdtCustomCss'), |
| 117 |
'wdtCustomJs' => get_option('wdtCustomJs'), |
| 118 |
'wdtMinifiedJs' => get_option('wdtMinifiedJs'), |
| 119 |
'wdtSumFunctionsLabel' => get_option('wdtSumFunctionsLabel'), |
| 120 |
'wdtAvgFunctionsLabel' => get_option('wdtAvgFunctionsLabel'), |
| 121 |
'wdtMinFunctionsLabel' => get_option('wdtMinFunctionsLabel'), |
| 122 |
'wdtMaxFunctionsLabel' => get_option('wdtMaxFunctionsLabel'), |
| 123 |
'wdtFontColorSettings' => get_option('wdtFontColorSettings') ? get_option('wdtFontColorSettings') : new stdClass(), |
| 124 |
'wdtAutoUpdateOption' => get_option('wdtAutoUpdateOption'), |
| 125 |
'wdtGoogleStableVersion' => get_option('wdtGoogleStableVersion'), |
| 126 |
); |
| 127 |
|
| 128 |
$usageSettings = UsageTracker::getSettings(new WpDataTablesCollector()); |
| 129 |
$settings['wdtUsageTrackingEnabled'] = !empty($usageSettings['usageTrackingEnabled']) ? 1 : 0; |
| 130 |
|
| 131 |
return $settings; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Returns languages |
| 136 |
*/ |
| 137 |
|
| 138 |
public static function getInterfaceLanguages(){ |
| 139 |
|
| 140 |
$languages = array(); |
| 141 |
|
| 142 |
foreach (glob(WDT_ROOT_PATH . 'source/lang/*.inc.php') as $lang_filename) { |
| 143 |
$lang_filename = str_replace(WDT_ROOT_PATH . 'source/lang/', '', $lang_filename); |
| 144 |
$name = ucwords(str_replace('_', ' ', $lang_filename)); |
| 145 |
$name = str_replace('.inc.php', '', $name); |
| 146 |
$languages[] = array('file' => $lang_filename, 'name' => $name); |
| 147 |
} |
| 148 |
|
| 149 |
return $languages; |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Returns system fonts |
| 154 |
*/ |
| 155 |
public static function wdtGetSystemFonts() { |
| 156 |
$systemFonts = array( |
| 157 |
'Georgia, serif', |
| 158 |
'Palatino Linotype, Book Antiqua, Palatino, serif', |
| 159 |
'Times New Roman, Times, serif', |
| 160 |
'Arial, Helvetica, sans-serif', |
| 161 |
'Impact, Charcoal, sans-serif', |
| 162 |
'Lucida Sans Unicode, Lucida Grande, sans-serif', |
| 163 |
'Tahoma, Geneva, sans-serif', |
| 164 |
'Verdana, Geneva, sans-serif', |
| 165 |
'Courier New, Courier, monospace', |
| 166 |
'Lucida Console, Monaco, monospace' |
| 167 |
); |
| 168 |
|
| 169 |
$systemFonts = apply_filters('wpdatatables_get_system_fonts', $systemFonts); |
| 170 |
|
| 171 |
return $systemFonts; |
| 172 |
} |
| 173 |
|
| 174 |
} |
| 175 |
|