From 435c3051d41e7b3ac047c3d5ed54f2613b5728d6 Mon Sep 17 00:00:00 2001 From: yaosanqi137 Date: Fri, 28 Aug 2026 12:30:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=86footer=E5=92=8C=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=8F=90=E4=BE=9B=E6=A8=A1=E5=9D=97=E7=9A=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=8F=98=E4=B8=BA=E5=90=8E=E5=8F=B0=E5=8F=AF=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/css/front-page.css | 12 + themes/ITStudioMainSite/footer.php | 92 ++++- themes/ITStudioMainSite/functions.php | 367 ++++++++++++++++++ themes/ITStudioMainSite/index.php | 138 ++----- 4 files changed, 488 insertions(+), 121 deletions(-) diff --git a/themes/ITStudioMainSite/assets/css/front-page.css b/themes/ITStudioMainSite/assets/css/front-page.css index afa5865..b7a2439 100644 --- a/themes/ITStudioMainSite/assets/css/front-page.css +++ b/themes/ITStudioMainSite/assets/css/front-page.css @@ -264,6 +264,13 @@ display: block; } +.service-icon .service-image { + width: 78px; + height: 78px; + display: block; + object-fit: contain; +} + .service-icon .svc-stroke, .service-icon .svc-muted, .service-icon .svc-accent { @@ -501,6 +508,11 @@ height: 58px; } + .service-icon .service-image { + width: 58px; + height: 58px; + } + .service-item span { font-size: 0.95rem; } diff --git a/themes/ITStudioMainSite/footer.php b/themes/ITStudioMainSite/footer.php index eef415f..30dedd0 100644 --- a/themes/ITStudioMainSite/footer.php +++ b/themes/ITStudioMainSite/footer.php @@ -1,36 +1,104 @@ diff --git a/themes/ITStudioMainSite/functions.php b/themes/ITStudioMainSite/functions.php index fdca133..3292b11 100644 --- a/themes/ITStudioMainSite/functions.php +++ b/themes/ITStudioMainSite/functions.php @@ -18,6 +18,373 @@ function itstudio_theme_setup() { } add_action('after_setup_theme', 'itstudio_theme_setup'); +function itstudio_get_site_content_defaults() { + return array( + 'footer_links' => array( + array( + 'title_cn' => '中国海洋大学', + 'title_en' => 'Ocean University of China', + 'url' => 'https://www.ouc.edu.cn', + ), + array( + 'title_cn' => '信息科学与工程学部', + 'title_en' => 'Faculty of Information Science and Engineering', + 'url' => 'https://it.ouc.edu.cn', + ), + ), + 'footer_contacts' => array( + array( + 'title_cn' => 'Email: Contact@itstudio.club', + 'title_en' => 'Email: Contact@itstudio.club', + 'url' => 'mailto:contact@itstudio.club', + ), + array( + 'title_cn' => 'GitHub', + 'title_en' => 'GitHub', + 'url' => 'https://github.com/ITStudioOUC/', + ), + ), + 'footer_addresses' => array( + array( + 'text_cn' => '中国海洋大学西海岸校区信息南楼五八创新创业工坊', + 'text_en' => '58 Workshop, South Information Building, West Coast Campus, Ocean University of China', + ), + ), + 'footer_icp' => array( + 'text_cn' => '桂ICP备2022004639号-2', + 'text_en' => '桂ICP备2022004639号-2', + 'url' => 'https://beian.miit.gov.cn/', + ), + 'footer_copyright' => array( + 'text_cn' => '中国海洋大学爱特工作室. 保留所有权利.', + 'text_en' => 'IT Studio, Ocean University of China. All rights reserved.', + ), + 'homepage_services' => array( + array('name_cn' => '资源站', 'name_en' => 'Resources', 'image_id' => 0), + array('name_cn' => '校内镜像站', 'name_en' => 'Mirror Site', 'image_id' => 0), + array('name_cn' => '代码托管', 'name_en' => 'Git Hosting', 'image_id' => 0), + array('name_cn' => 'Minecraft服务器', 'name_en' => 'Minecraft Server', 'image_id' => 0), + array('name_cn' => 'OUC论坛', 'name_en' => 'OUC Forum', 'image_id' => 0), + array('name_cn' => '电脑维修', 'name_en' => 'PC Repair', 'image_id' => 0), + array('name_cn' => '五八工坊预约', 'name_en' => 'Workshop Booking', 'image_id' => 0), + array('name_cn' => 'OUC便民服务', 'name_en' => 'OUC Services', 'image_id' => 0), + ), + ); +} + +function itstudio_get_site_content_settings() { + $stored = get_option('itstudio_site_content_settings', false); + if ($stored === false) { + return itstudio_get_site_content_defaults(); + } + + $defaults = itstudio_get_site_content_defaults(); + $stored = is_array($stored) ? $stored : array(); + return array( + 'footer_links' => isset($stored['footer_links']) && is_array($stored['footer_links']) ? $stored['footer_links'] : array(), + 'footer_contacts' => isset($stored['footer_contacts']) && is_array($stored['footer_contacts']) ? $stored['footer_contacts'] : array(), + 'footer_addresses' => isset($stored['footer_addresses']) && is_array($stored['footer_addresses']) ? $stored['footer_addresses'] : array(), + 'footer_icp' => isset($stored['footer_icp']) && is_array($stored['footer_icp']) ? array_merge($defaults['footer_icp'], $stored['footer_icp']) : array_merge($defaults['footer_icp'], array()), + 'footer_copyright' => isset($stored['footer_copyright']) && is_array($stored['footer_copyright']) ? array_merge($defaults['footer_copyright'], $stored['footer_copyright']) : array_merge($defaults['footer_copyright'], array()), + 'homepage_services' => isset($stored['homepage_services']) && is_array($stored['homepage_services']) ? $stored['homepage_services'] : array(), + ); +} + +function itstudio_site_content_allowed_attachment($attachment_id) { + $attachment_id = absint($attachment_id); + if ($attachment_id <= 0 || !current_user_can('edit_post', $attachment_id)) { + return false; + } + + $mime = (string) get_post_mime_type($attachment_id); + return strpos($mime, 'image/') === 0; +} + +function itstudio_sanitize_site_content_settings($input) { + $input = is_array($input) ? $input : array(); + $clean = array( + 'footer_links' => array(), + 'footer_contacts' => array(), + 'footer_addresses' => array(), + 'footer_icp' => array( + 'text_cn' => '', + 'text_en' => '', + 'url' => '', + ), + 'footer_copyright' => array( + 'text_cn' => '', + 'text_en' => '', + ), + 'homepage_services' => array(), + ); + + foreach (array('footer_links' => 8, 'footer_contacts' => 4) as $key => $limit) { + $rows = isset($input[$key]) && is_array($input[$key]) ? $input[$key] : array(); + foreach (array_slice($rows, 0, $limit) as $row) { + if (!is_array($row)) { + continue; + } + + $item = array( + 'title_cn' => sanitize_text_field($row['title_cn'] ?? ''), + 'title_en' => sanitize_text_field($row['title_en'] ?? ''), + 'url' => esc_url_raw($row['url'] ?? ''), + ); + if ($item['title_cn'] !== '' || $item['title_en'] !== '' || $item['url'] !== '') { + $clean[$key][] = $item; + } + } + } + + $address_rows = isset($input['footer_addresses']) && is_array($input['footer_addresses']) ? $input['footer_addresses'] : array(); + foreach (array_slice($address_rows, 0, 2) as $row) { + if (!is_array($row)) { + continue; + } + + $item = array( + 'text_cn' => sanitize_textarea_field($row['text_cn'] ?? ''), + 'text_en' => sanitize_textarea_field($row['text_en'] ?? ''), + ); + if ($item['text_cn'] !== '' || $item['text_en'] !== '') { + $clean['footer_addresses'][] = $item; + } + } + + $icp = isset($input['footer_icp']) && is_array($input['footer_icp']) ? $input['footer_icp'] : array(); + $clean['footer_icp'] = array( + 'text_cn' => sanitize_text_field($icp['text_cn'] ?? ''), + 'text_en' => sanitize_text_field($icp['text_en'] ?? ''), + 'url' => esc_url_raw($icp['url'] ?? ''), + ); + + $copyright = isset($input['footer_copyright']) && is_array($input['footer_copyright']) ? $input['footer_copyright'] : array(); + $clean['footer_copyright'] = array( + 'text_cn' => sanitize_text_field($copyright['text_cn'] ?? ''), + 'text_en' => sanitize_text_field($copyright['text_en'] ?? ''), + ); + + $service_rows = isset($input['homepage_services']) && is_array($input['homepage_services']) ? $input['homepage_services'] : array(); + foreach (array_slice($service_rows, 0, 8) as $row) { + if (!is_array($row)) { + continue; + } + + $image_id = absint($row['image_id'] ?? 0); + $item = array( + 'name_cn' => sanitize_text_field($row['name_cn'] ?? ''), + 'name_en' => sanitize_text_field($row['name_en'] ?? ''), + 'image_id' => itstudio_site_content_allowed_attachment($image_id) ? $image_id : 0, + ); + if ($item['name_cn'] !== '' || $item['name_en'] !== '' || $item['image_id'] > 0) { + $clean['homepage_services'][] = $item; + } + } + + return $clean; +} + +function itstudio_register_site_content_settings() { + register_setting('itstudio_site_content', 'itstudio_site_content_settings', array( + 'type' => 'array', + 'sanitize_callback' => 'itstudio_sanitize_site_content_settings', + 'default' => itstudio_get_site_content_defaults(), + )); + + add_settings_section( + 'itstudio_site_content_intro', + __('站点内容', 'itstudio'), + static function () { + echo '

' . esc_html__('管理页脚内容和首页“服务提供”模块。留空的项目不会在前台显示。', 'itstudio') . '

'; + }, + 'itstudio-site-content' + ); + + add_settings_field('itstudio_footer_links', __('友情链接', 'itstudio'), 'itstudio_render_footer_links_field', 'itstudio-site-content', 'itstudio_site_content_intro'); + add_settings_field('itstudio_footer_contacts', __('联系我们', 'itstudio'), 'itstudio_render_footer_contacts_field', 'itstudio-site-content', 'itstudio_site_content_intro'); + add_settings_field('itstudio_footer_addresses', __('办公地址', 'itstudio'), 'itstudio_render_footer_addresses_field', 'itstudio-site-content', 'itstudio_site_content_intro'); + add_settings_field('itstudio_footer_bottom', __('备案与版权', 'itstudio'), 'itstudio_render_footer_bottom_field', 'itstudio-site-content', 'itstudio_site_content_intro'); + add_settings_field('itstudio_homepage_services', __('首页服务提供', 'itstudio'), 'itstudio_render_homepage_services_field', 'itstudio-site-content', 'itstudio_site_content_intro'); +} +add_action('admin_init', 'itstudio_register_site_content_settings'); + +function itstudio_register_site_content_page() { + add_theme_page( + __('站点内容设置', 'itstudio'), + __('站点内容设置', 'itstudio'), + 'manage_options', + 'itstudio-site-content', + 'itstudio_render_site_content_page' + ); +} +add_action('admin_menu', 'itstudio_register_site_content_page'); + +function itstudio_site_content_admin_rows($key, $limit) { + $settings = itstudio_get_site_content_settings(); + $rows = isset($settings[$key]) && is_array($settings[$key]) ? array_values($settings[$key]) : array(); + while (count($rows) < $limit) { + $rows[] = array(); + } + + return array_slice($rows, 0, $limit); +} + +function itstudio_render_footer_links_field() { + $rows = itstudio_site_content_admin_rows('footer_links', 8); + echo '

' . esc_html__('最多 8 条,每条支持中英文名称和链接。', 'itstudio') . '

'; + foreach ($rows as $index => $row) { + itstudio_render_site_content_link_row('footer_links', $index, $row); + } +} + +function itstudio_render_footer_contacts_field() { + $rows = itstudio_site_content_admin_rows('footer_contacts', 4); + echo '

' . esc_html__('最多 4 条,每条支持中英文文字和链接;链接可填写 mailto: 地址。', 'itstudio') . '

'; + foreach ($rows as $index => $row) { + itstudio_render_site_content_link_row('footer_contacts', $index, $row); + } +} + +function itstudio_render_site_content_link_row($key, $index, $row) { + $base = 'itstudio_site_content_settings[' . $key . '][' . $index . ']'; + $title_cn = (string) ($row['title_cn'] ?? ''); + $title_en = (string) ($row['title_en'] ?? ''); + $url = (string) ($row['url'] ?? ''); + echo '
'; + printf('', esc_attr($base), esc_attr($title_cn), esc_attr__('中文名称', 'itstudio')); + printf('', esc_attr($base), esc_attr($title_en), esc_attr__('English label', 'itstudio')); + printf('', esc_attr($base), esc_attr($url)); + echo '
'; +} + +function itstudio_render_footer_addresses_field() { + $rows = itstudio_site_content_admin_rows('footer_addresses', 2); + echo '

' . esc_html__('最多 2 条,每条支持中英文地址。', 'itstudio') . '

'; + foreach ($rows as $index => $row) { + $base = 'itstudio_site_content_settings[footer_addresses][' . $index . ']'; + printf('
', esc_attr($base), esc_attr__('中文地址', 'itstudio'), esc_textarea($row['text_cn'] ?? ''), esc_attr($base), esc_attr__('English address', 'itstudio'), esc_textarea($row['text_en'] ?? '')); + } +} + +function itstudio_render_footer_bottom_field() { + $settings = itstudio_get_site_content_settings(); + $icp = $settings['footer_icp']; + $copyright = $settings['footer_copyright']; + echo '

' . esc_html__('备案信息', 'itstudio') . '

'; + printf('
', esc_attr($icp['text_cn'] ?? ''), esc_attr__('中文备案信息', 'itstudio'), esc_attr($icp['text_en'] ?? ''), esc_attr__('English filing text', 'itstudio'), esc_attr($icp['url'] ?? '')); + echo '

' . esc_html__('版权信息', 'itstudio') . '

'; + printf('

%s

', esc_attr($copyright['text_cn'] ?? ''), esc_attr__('中文版权信息', 'itstudio'), esc_attr($copyright['text_en'] ?? ''), esc_attr__('English copyright text', 'itstudio'), esc_html__('前台会自动在版权信息前添加当前年份。', 'itstudio')); +} + +function itstudio_render_homepage_services_field() { + $rows = itstudio_site_content_admin_rows('homepage_services', 8); + echo '

' . esc_html__('最多 8 条。设置中英文名称并从媒体库选择图像,支持 PNG、JPG、WebP 和 SVG。', 'itstudio') . '

'; + foreach ($rows as $index => $row) { + $base = 'itstudio_site_content_settings[homepage_services][' . $index . ']'; + $image_id = absint($row['image_id'] ?? 0); + $image_url = $image_id > 0 ? wp_get_attachment_image_url($image_id, 'thumbnail') : ''; + if (!$image_url && $image_id > 0) { + $image_url = wp_get_attachment_url($image_id); + } + echo '
'; + printf('', esc_attr($base), esc_attr($row['name_cn'] ?? ''), esc_attr__('中文名称', 'itstudio')); + printf('', esc_attr($base), esc_attr($row['name_en'] ?? ''), esc_attr__('English name', 'itstudio')); + echo '
'; + printf('', $index, esc_attr($base), $image_id); + printf(' ', $index, $index, esc_html__('选择图像', 'itstudio')); + printf('', $index, $index, esc_html__('清除', 'itstudio')); + printf('%s', $index, $image_url ? '' : ''); + echo '
'; + } +} + +function itstudio_render_site_content_page() { + if (!current_user_can('manage_options')) { + return; + } + ?> +
+

+
+ +
+
+ id !== 'appearance_page_itstudio-site-content') { + return; + } + ?> + +

-
-
- + + 0 ? wp_get_attachment_image_url($image_id, 'medium') : ''; + if (!$image_url && $image_id > 0) { + $image_url = wp_get_attachment_url($image_id); + } + if (!is_string($image_url) || $image_url === '') { + $image_url = get_template_directory_uri() . '/resources/it_logo_2024.svg'; + } + ?> +
+
+ +
+
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
+