From 4af400fd75edf280e1490d2ecc41023348acc6a1 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Tue, 1 May 2018 06:51:23 -0500 Subject: [PATCH] Refactored some Downloads plugin code --- .../handlers/NginxSecureLinkMd5Decorator.php | 2 +- e107_plugins/download/includes/admin.php | 79 ++++++++++--------- .../shim_http_build_url.php | 0 3 files changed, 43 insertions(+), 38 deletions(-) rename e107_plugins/download/{includes => vendor}/shim_http_build_url.php (100%) diff --git a/e107_plugins/download/handlers/NginxSecureLinkMd5Decorator.php b/e107_plugins/download/handlers/NginxSecureLinkMd5Decorator.php index 603ce55f2..7e36cbace 100644 --- a/e107_plugins/download/handlers/NginxSecureLinkMd5Decorator.php +++ b/e107_plugins/download/handlers/NginxSecureLinkMd5Decorator.php @@ -46,7 +46,7 @@ class NginxSecureLinkMd5Decorator implements SecureLinkDecorator $query_args['md5'] = str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode(md5($evaluation, true))); if (strpos($prefs['download_security_expression'], '$secure_link_expires') !== false) $query_args['expires'] = $expiry; - require_once(__DIR__.'/../includes/shim_http_build_url.php'); + require_once(__DIR__ . '/../vendor/shim_http_build_url.php'); return http_build_url($url_parts, array('query' => http_build_query($query_args))); } } \ No newline at end of file diff --git a/e107_plugins/download/includes/admin.php b/e107_plugins/download/includes/admin.php index 54b0e2abc..d8548109e 100644 --- a/e107_plugins/download/includes/admin.php +++ b/e107_plugins/download/includes/admin.php @@ -1137,31 +1137,28 @@ $columnInfo = array( global $admin_log,$pref; $tp = e107::getParser(); + + $expected_params = array( + 'download_php', 'download_view', 'download_sort', 'download_order', + 'mirror_order', 'recent_download_days', 'agree_flag', 'download_email', + 'agree_text', 'download_denied', 'download_reportbroken', + 'download_security_mode', 'download_security_expression', 'download_security_link_expiry' + ); $temp = array(); - $temp['download_php'] = $_POST['download_php']; - $temp['download_view'] = $_POST['download_view']; - $temp['download_sort'] = $_POST['download_sort']; - $temp['download_order'] = $_POST['download_order']; - $temp['mirror_order'] = $_POST['mirror_order']; - $temp['recent_download_days'] = $_POST['recent_download_days']; - $temp['agree_flag'] = $_POST['agree_flag']; - $temp['download_email'] = $_POST['download_email']; - $temp['agree_text'] = $tp->toDB($_POST['agree_text']); - $temp['download_denied'] = $tp->toDB($_POST['download_denied']); - $temp['download_reportbroken'] = $_POST['download_reportbroken']; - - if ($_POST['download_subsub']) $temp['download_subsub'] = '1'; else $temp['download_subsub'] = '0'; - if ($_POST['download_incinfo']) $temp['download_incinfo'] = '1'; else $temp['download_incinfo'] = '0'; - - if ($_POST['download_security_mode'] === 'nginx-secure_link_md5') + foreach($expected_params as $expected_param) { - $temp['download_security_mode'] = $_POST['download_security_mode']; - $temp['download_security_expression'] = $_POST['download_security_expression']; - $temp['download_security_link_expiry'] = $_POST['download_security_link_expiry']; + $temp[$expected_param] = $_POST[$expected_param]; } - else + + $temp['download_subsub'] = $_POST['download_subsub'] ? '1' : '0'; + $temp['download_incinfo'] = $_POST['download_incinfo'] ? '1' : '0'; + + if ($_POST['download_security_mode'] !== 'nginx-secure_link_md5') { + unset($temp['download_security_mode']); + unset($temp['download_security_expression']); + unset($temp['download_security_link_expiry']); e107::getConfig('core')->removePref('download_security_mode'); e107::getConfig('core')->removePref('download_security_expression'); e107::getConfig('core')->removePref('download_security_link_expiry'); @@ -2110,22 +2107,33 @@ $columnInfo = array( } } + private function supported_secure_link_variables_html() + { + require_once(__DIR__."/../handlers/NginxSecureLinkMd5Decorator.php"); + $supported_secure_link_variables_html = ""; + return $supported_secure_link_variables_html; + } + + private function mirror_order_options_html($pref) + { + return ($pref['mirror_order'] == "0" ? "" : ""). + ($pref['mirror_order'] == "1" ? "" : ""). + ($pref['mirror_order'] == "2" ? "" : ""); + } + function show_download_options() { global $pref, $ns; - require_once(__DIR__."/../handlers/NginxSecureLinkMd5Decorator.php"); - $supported_secure_link_variables_html = ""; - - require_once(e_HANDLER."form_handler.php"); - $frm = new e_form(true); //enable inner tabindex counter - - $agree_flag = $pref['agree_flag']; + require_once(e_HANDLER."form_handler.php"); + $frm = new e_form(true); //enable inner tabindex counter + + $agree_flag = $pref['agree_flag']; $agree_text = $pref['agree_text']; $c = $pref['download_php'] ? " checked = 'checked' " : ""; $sacc = (varset($pref['download_incinfo'],0) == '1') ? " checked = 'checked' " : ""; @@ -2196,10 +2204,7 @@ $columnInfo = array( ".DOWLAN_160." - ".$this->mirror_order_options_html($pref)." @@ -2275,7 +2280,7 @@ $columnInfo = array( ".LAN_DL_SECURITY_NGINX_SUPPORTED_VARIABLES_TOGGLE." diff --git a/e107_plugins/download/includes/shim_http_build_url.php b/e107_plugins/download/vendor/shim_http_build_url.php similarity index 100% rename from e107_plugins/download/includes/shim_http_build_url.php rename to e107_plugins/download/vendor/shim_http_build_url.php