diff --git a/inc/options-framework/js/options-custom.js b/inc/options-framework/js/options-custom.js index 3d1cc50..aeea43c 100755 --- a/inc/options-framework/js/options-custom.js +++ b/inc/options-framework/js/options-custom.js @@ -4,178 +4,187 @@ */ jQuery(document).ready(function ($) { + $('input[id^="s_"]').click(function () { + jQuery("#section-" + this.id + "_url").fadeToggle(400); + jQuery("#section-" + this.id + "_links").fadeToggle(400); + }); - $('input[id^="s_"]').click(function () { - jQuery('#section-' + this.id + '_url').fadeToggle(400) - jQuery('#section-' + this.id + '_links').fadeToggle(400) - }) + for (i = 0; i < $('input[id^="s_"]' + ":checked").length; i++) { + let id = $('input[id^="s_"]' + ":checked")[i].id; + $("#section-" + id + "_url").show(); + $("#section-" + id + "_links").show(); + } - for (i = 0; i < $('input[id^="s_"]' + ':checked').length; i++) { - let id = $('input[id^="s_"]' + ':checked')[i].id - $('#section-' + id + '_url').show() - $('#section-' + id + '_links').show() - } + jQuery("#g_carousel").click(function () { + for (let i = 1; i < 6; i++) { + jQuery("#section-c_i_" + [i]).fadeToggle(400); + jQuery("#section-c_u_" + [i]).fadeToggle(400); + } + }); - jQuery('#g_carousel').click(function () { - for (let i = 1; i < 6; i++) { - jQuery('#section-c_i_' + [i]).fadeToggle(400) - jQuery('#section-c_u_' + [i]).fadeToggle(400) - } - }) + if (jQuery("#g_carousel:checked").val() !== undefined) { + for (let i = 1; i < 6; i++) { + console.log("#c_i_" + [i]); + jQuery("#section-c_i_" + [i]).show(); + jQuery("#section-c_u_" + [i]).show(); + } + } - if (jQuery('#g_carousel:checked').val() !== undefined) { - for (let i = 1; i < 6; i++) { - console.log('#c_i_' + [i]) - jQuery('#section-c_i_' + [i]).show() - jQuery('#section-c_u_' + [i]).show() - } - } + jQuery("#g_cos").click(function () { + jQuery("#section-g_cos_bucketname").fadeToggle(400); + jQuery("#section-g_cos_url").fadeToggle(400); + jQuery("#section-g_cos_accesskey").fadeToggle(400); + jQuery("#section-g_cos_secretkey").fadeToggle(400); + }); - jQuery('#g_cos').click(function () { - jQuery('#section-g_cos_bucketname').fadeToggle(400) - jQuery('#section-g_cos_url').fadeToggle(400) - jQuery('#section-g_cos_accesskey').fadeToggle(400) - jQuery('#section-g_cos_secretkey').fadeToggle(400) - }) + if (jQuery("#g_cos:checked").val() !== undefined) { + jQuery("#section-g_cos_bucketname").show(); + jQuery("#section-g_cos_url").show(); + jQuery("#section-g_cos_accesskey").show(); + jQuery("#section-g_cos_secretkey").show(); + } - if (jQuery('#g_cos:checked').val() !== undefined) { - jQuery('#section-g_cos_bucketname').show() - jQuery('#section-g_cos_url').show() - jQuery('#section-g_cos_accesskey').show() - jQuery('#section-g_cos_secretkey').show() - } + jQuery("#g_cc_switch").click(function () { + jQuery("#section-g_cc").fadeToggle(400); + }); - jQuery('#g_cc_switch').click(function () { - jQuery('#section-g_cc').fadeToggle(400) - }) + if (jQuery("#g_cc_switch:checked").val() !== undefined) { + jQuery("#section-g_cc").show(); + } - if (jQuery('#g_cc_switch:checked').val() !== undefined) { - jQuery('#section-g_cc').show() - } + jQuery("#g_donate").click(function () { + jQuery("#section-g_donate_alipay").fadeToggle(400); + jQuery("#section-g_donate_wechat").fadeToggle(400); + }); - jQuery('#g_donate').click(function () { - jQuery('#section-g_donate_alipay').fadeToggle(400) - jQuery('#section-g_donate_wechat').fadeToggle(400) - }) + if (jQuery("#g_donate:checked").val() !== undefined) { + jQuery("#section-g_donate_alipay").show(); + jQuery("#section-g_donate_wechat").show(); + } - if (jQuery('#g_donate:checked').val() !== undefined) { - jQuery('#section-g_donate_alipay').show() - jQuery('#section-g_donate_wechat').show() - } + jQuery("#m_smtp").click(function () { + jQuery("#section-m_host").fadeToggle(400); + jQuery("#section-m_sec").fadeToggle(400); + jQuery("#section-m_port").fadeToggle(400); + jQuery("#section-m_username").fadeToggle(400); + jQuery("#section-m_passwd").fadeToggle(400); + jQuery("#section-m_sendmail").fadeToggle(400); + }); - jQuery('#m_smtp').click(function () { - jQuery('#section-m_host').fadeToggle(400) - jQuery('#section-m_sec').fadeToggle(400) - jQuery('#section-m_port').fadeToggle(400) - jQuery('#section-m_username').fadeToggle(400) - jQuery('#section-m_passwd').fadeToggle(400) - jQuery('#section-m_sendmail').fadeToggle(400) - }) + if (jQuery("#m_smtp:checked").val() !== undefined) { + jQuery("#section-m_host").show(); + jQuery("#section-m_sec").show(); + jQuery("#section-m_port").show(); + jQuery("#section-m_username").show(); + jQuery("#section-m_passwd").show(); + jQuery("#section-m_sendmail").show(); + } - if (jQuery('#m_smtp:checked').val() !== undefined) { - jQuery('#section-m_host').show() - jQuery('#section-m_sec').show() - jQuery('#section-m_port').show() - jQuery('#section-m_username').show() - jQuery('#section-m_passwd').show() - jQuery('#section-m_sendmail').show() - } + jQuery("#g_thumbnail").click(function () { + jQuery("#section-g_postthumbnail").fadeToggle(400); + }); - jQuery('#g_thumbnail').click(function () { - jQuery('#section-g_postthumbnail').fadeToggle(400) - }) + if (jQuery("#g_thumbnail:checked").val() !== undefined) { + jQuery("#section-g_postthumbnail").show(); + } - if (jQuery('#g_thumbnail:checked').val() !== undefined) { - jQuery('#section-g_postthumbnail').show() - } + jQuery("#top_select").change(function () { + if (jQuery("#top_select").val() == "color") { + jQuery("#section-top_color").fadeIn(400); + jQuery("#section-top_img").fadeOut(400); + jQuery("#section-top_title").fadeOut(400); + jQuery("#section-top_describe").fadeOut(400); + } else { + jQuery("#section-top_color").fadeOut(400); + jQuery("#section-top_img").fadeIn(400); + jQuery("#section-top_title").fadeIn(400); + jQuery("#section-top_describe").fadeIn(400); + } + }); - jQuery('#top_select').change(function () { - if (jQuery("#top_select").val() == 'color') { - jQuery('#section-top_color').fadeIn(400) - jQuery('#section-top_img').fadeOut(400) - jQuery('#section-top_title').fadeOut(400) - jQuery('#section-top_describe').fadeOut(400) - } else { - jQuery('#section-top_color').fadeOut(400) - jQuery('#section-top_img').fadeIn(400) - jQuery('#section-top_title').fadeIn(400) - jQuery('#section-top_describe').fadeIn(400) - } - }) + if (jQuery("#top_select").val() == "color") { + jQuery("#section-top_color").show(); + jQuery("#section-top_img").hide(); + jQuery("#section-top_title").hide(); + jQuery("#section-top_describe").hide(); + } else { + jQuery("#section-top_color").hide(); + jQuery("#section-top_img").show(); + jQuery("#section-top_title").show(); + jQuery("#section-top_describe").show(); + } - if (jQuery('#top_select').val() == 'color') { - jQuery('#section-top_color').show() - jQuery('#section-top_img').hide() - jQuery('#section-top_title').hide() - jQuery('#section-top_describe').hide() - } else { - jQuery('#section-top_color').hide() - jQuery('#section-top_img').show() - jQuery('#section-top_title').show() - jQuery('#section-top_describe').show() - } + jQuery("#g_renameother").click(function () { + jQuery("#section-g_renameother_mime").fadeToggle(400); + jQuery("#section-g_renameother_prdfix").fadeToggle(400); + }); - // Loads the color pickers - $('.of-color').wpColorPicker() + if (jQuery("#g_renameother:checked").val() !== undefined) { + jQuery("#section-g_renameother_mime").show(); + jQuery("#section-g_renameother_prdfix").show(); + } - // Image Options - $('.of-radio-img-img').click(function () { - $(this).parent().parent().find('.of-radio-img-img').removeClass('of-radio-img-selected') - $(this).addClass('of-radio-img-selected') - }) + // Loads the color pickers + $(".of-color").wpColorPicker(); - $('.of-radio-img-label').hide() - $('.of-radio-img-img').show() - $('.of-radio-img-radio').hide() + // Image Options + $(".of-radio-img-img").click(function () { + $(this) + .parent() + .parent() + .find(".of-radio-img-img") + .removeClass("of-radio-img-selected"); + $(this).addClass("of-radio-img-selected"); + }); - // Loads tabbed sections if they exist - if ($('.nav-tab-wrapper').length > 0) { - options_framework_tabs() - } + $(".of-radio-img-label").hide(); + $(".of-radio-img-img").show(); + $(".of-radio-img-radio").hide(); - function options_framework_tabs () { + // Loads tabbed sections if they exist + if ($(".nav-tab-wrapper").length > 0) { + options_framework_tabs(); + } - var $group = $('.group'), - $navtabs = $('.nav-tab-wrapper a'), - active_tab = '' + function options_framework_tabs() { + var $group = $(".group"), + $navtabs = $(".nav-tab-wrapper a"), + active_tab = ""; - // Hides all the .group sections to start - $group.hide() + // Hides all the .group sections to start + $group.hide(); - // Find if a selected tab is saved in localStorage - if (typeof (localStorage) != 'undefined') { - active_tab = localStorage.getItem('active_tab') - } + // Find if a selected tab is saved in localStorage + if (typeof localStorage != "undefined") { + active_tab = localStorage.getItem("active_tab"); + } - // If active tab is saved and exists, load it's .group - if (active_tab != '' && $(active_tab).length) { - $(active_tab).fadeIn() - $(active_tab + '-tab').addClass('nav-tab-active') - } else { - $('.group:first').fadeIn() - $('.nav-tab-wrapper a:first').addClass('nav-tab-active') - } + // If active tab is saved and exists, load it's .group + if (active_tab != "" && $(active_tab).length) { + $(active_tab).fadeIn(); + $(active_tab + "-tab").addClass("nav-tab-active"); + } else { + $(".group:first").fadeIn(); + $(".nav-tab-wrapper a:first").addClass("nav-tab-active"); + } - // Bind tabs clicks - $navtabs.click(function (e) { + // Bind tabs clicks + $navtabs.click(function (e) { + e.preventDefault(); - e.preventDefault() + // Remove active class from all tabs + $navtabs.removeClass("nav-tab-active"); - // Remove active class from all tabs - $navtabs.removeClass('nav-tab-active') + $(this).addClass("nav-tab-active").blur(); - $(this).addClass('nav-tab-active').blur() + if (typeof localStorage != "undefined") { + localStorage.setItem("active_tab", $(this).attr("href")); + } - if (typeof (localStorage) != 'undefined') { - localStorage.setItem('active_tab', $(this).attr('href')) - } + var selected = $(this).attr("href"); - var selected = $(this).attr('href') - - $group.hide() - $(selected).fadeIn() - - }) - } - -}) \ No newline at end of file + $group.hide(); + $(selected).fadeIn(); + }); + } +}); diff --git a/inc/theme-core.php b/inc/theme-core.php index a1815bc..80759dc 100644 --- a/inc/theme-core.php +++ b/inc/theme-core.php @@ -3,7 +3,7 @@ * 核心函数 * @author Seaton Jiang * @license MIT License - * @version 2021.01.17 + * @version 2021.02.18 */ if (kratos_option('g_cdn', false)) { @@ -206,4 +206,47 @@ if (kratos_option('g_removeimgsize', false)) { remove_image_size('1536x1536'); remove_image_size('2048x2048'); +} + +// 媒体文件使用 md5 值重命名,指定文件前缀 +add_filter('wp_handle_upload_prefilter', 'custom_upload_filter'); + +function custom_upload_filter($file) +{ + $info = pathinfo($file['name']); + + $ext = '.' . $info['extension']; + + $prdfix = kratos_option('g_renameother_prdfix', '') . '-'; + + $img_mimes = array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'webp', 'svg'); + + $str = kratos_option('g_renameother_mime', ''); + $arr = explode("|", $str); + $arr = array_filter($arr); + + foreach ($arr as $value) { + $compressed_mimes[] = $value; + } + + if (kratos_option('g_renameimg', false)) { + foreach ($img_mimes as $img_mime) { + if ($info['extension'] == $img_mime) { + $charid = strtolower(md5($file['name'])); + $hyphen = chr(45); + $uuid = substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12); + $file['name'] = $uuid . $ext; + } + } + } + + if (kratos_option('g_renameother', false)) { + foreach ($compressed_mimes as $compressed_mime) { + if ($info['extension'] == $compressed_mime) { + $file['name'] = $prdfix . $file['name']; + } + } + } + + return $file; } \ No newline at end of file diff --git a/inc/theme-options.php b/inc/theme-options.php index 293a8ba..dd0dd81 100644 --- a/inc/theme-options.php +++ b/inc/theme-options.php @@ -3,7 +3,7 @@ * 主题选项 * @author Seaton Jiang * @license MIT License - * @version 2020.12.14 + * @version 2021.02.18 */ function getrobots() @@ -20,6 +20,29 @@ function getrobots() return $robots; } +function getdomain($url) +{ + $rs = parse_url($url); + if (!isset($rs['host'])) { + return null; + } + + $main_url = $rs['host']; + if (!strcmp(long2ip(sprintf('%u', ip2long($main_url))), $main_url)) { + return $main_url; + } else { + $arr = explode('.', $main_url); + $count = count($arr); + $endArr = array('com', 'net', 'org'); + if (in_array($arr[$count - 2], $endArr)) { + $domain = $arr[$count - 3] . '.' . $arr[$count - 2] . '.' . $arr[$count - 1]; + } else { + $domain = $arr[$count - 2] . '.' . $arr[$count - 1]; + } + return $domain; + } +} + function kratos_options() { $sitename = get_bloginfo('name'); @@ -119,6 +142,37 @@ function kratos_options() 'type' => 'checkbox', ); + $options[] = array( + 'name' => __('自定义媒体文件名', 'kratos'), + 'desc' => __('把图片类型的文件名改为 MD5 值命名', 'kratos'), + 'id' => 'g_renameimg', + 'std' => '0', + 'type' => 'checkbox', + ); + + $options[] = array( + 'desc' => __('把指定类型的文件名增加自定义前缀命名', 'kratos'), + 'id' => 'g_renameother', + 'type' => 'checkbox', + ); + + $options[] = array( + 'desc' => __('请输入需要添加的前缀,前缀与文件名之间默认用 - 连接', 'kratos'), + 'id' => 'g_renameother_prdfix', + 'std' => getdomain(home_url()), + 'class' => 'hidden', + 'type' => 'text', + ); + + $options[] = array( + 'desc' => __('请输入需要修改的类型,每个类型之间用 | 隔开', 'kratos'), + 'id' => 'g_renameother_mime', + 'std' => 'tar|zip|gz|gzip|rar|7z', + 'class' => 'hidden', + 'type' => 'text', + ); + + $options[] = array( 'name' => __('禁止生成缩略图', 'kratos'), 'desc' => __('是否禁止生成多种尺寸图片资源', 'kratos'),