feat: 将footer和服务提供模块的信息变为后台可编辑的

This commit is contained in:
2026-08-28 12:30:25 +08:00
parent 0c6e5d6960
commit 435c3051d4
4 changed files with 488 additions and 121 deletions
@@ -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;
}
+80 -12
View File
@@ -1,36 +1,104 @@
<footer class="site-footer">
<div class="container">
<?php $site_content = itstudio_get_site_content_settings(); ?>
<div class="footer-content">
<div class="footer-section">
<h3 data-cn="友情链接" data-en="Links"></h3>
<ul class="footer-links">
<li><a href="https://www.ouc.edu.cn" target="_blank" rel="noopener" data-cn="中国海洋大学" data-en="Ocean University of China"></a></li>
<li><a href="https://it.ouc.edu.cn" target="_blank" rel="noopener" data-cn="信息科学与工程学部" data-en="Faculty of Information Science and Engineering"></a></li>
<?php foreach ((array) ($site_content['footer_links'] ?? array()) as $link) : ?>
<?php
$url = esc_url((string) ($link['url'] ?? ''));
$title_cn = trim((string) ($link['title_cn'] ?? ''));
$title_en = trim((string) ($link['title_en'] ?? ''));
if ($url === '' || ($title_cn === '' && $title_en === '')) {
continue;
}
if ($title_cn === '') {
$title_cn = $title_en;
}
if ($title_en === '') {
$title_en = $title_cn;
}
?>
<li><a href="<?php echo $url; ?>" target="_blank" rel="noopener noreferrer" data-cn="<?php echo esc_attr($title_cn); ?>" data-en="<?php echo esc_attr($title_en); ?>"></a></li>
<?php endforeach; ?>
</ul>
</div>
<div class="footer-section">
<h3 data-cn="联系我们" data-en="Contact Us"></h3>
<ul class="footer-links">
<li><a href="mailto:contact@itstudio.club" target="_blank" rel="noopener">Email: Contact@itstudio.club</a></li>
<li><a href="https://github.com/ITStudioOUC/" target="_blank" rel="noopener">GitHub</a></li>
<?php foreach ((array) ($site_content['footer_contacts'] ?? array()) as $contact) : ?>
<?php
$url = esc_url((string) ($contact['url'] ?? ''));
$title_cn = trim((string) ($contact['title_cn'] ?? ''));
$title_en = trim((string) ($contact['title_en'] ?? ''));
if ($url === '' || ($title_cn === '' && $title_en === '')) {
continue;
}
if ($title_cn === '') {
$title_cn = $title_en;
}
if ($title_en === '') {
$title_en = $title_cn;
}
?>
<li><a href="<?php echo $url; ?>" target="_blank" rel="noopener noreferrer" data-cn="<?php echo esc_attr($title_cn); ?>" data-en="<?php echo esc_attr($title_en); ?>"></a></li>
<?php endforeach; ?>
</ul>
</div>
<div class="footer-section footer-address">
<h3 data-cn="办公地址" data-en="Office Address"></h3>
<p class="footer-address-text">
<span
data-cn="中国海洋大学西海岸校区信息南楼五八创新创业工坊"
data-en="58 Workshop, South Information Building, West Coast Campus, Ocean University of China
"></span>
</p>
<?php foreach ((array) ($site_content['footer_addresses'] ?? array()) as $address) : ?>
<?php
$text_cn = trim((string) ($address['text_cn'] ?? ''));
$text_en = trim((string) ($address['text_en'] ?? ''));
if ($text_cn === '' && $text_en === '') {
continue;
}
if ($text_cn === '') {
$text_cn = $text_en;
}
if ($text_en === '') {
$text_en = $text_cn;
}
?>
<p class="footer-address-text" data-cn="<?php echo esc_attr($text_cn); ?>" data-en="<?php echo esc_attr($text_en); ?>"></p>
<?php endforeach; ?>
</div>
</div>
<div class="footer-bottom">
<a href="https://beian.miit.gov.cn/" target="_blank" rel="noopener" data-cn="桂ICP备2022004639号-2" data-en="桂ICP备2022004639号-2"></a>
<p data-cn="&copy; <?php echo date('Y'); ?> 中国海洋大学爱特工作室. 保留所有权利." data-en="&copy; <?php echo date('Y'); ?> IT Studio, Ocean University of China. All rights reserved."></p>
<?php
$icp = (array) ($site_content['footer_icp'] ?? array());
$icp_cn = trim((string) ($icp['text_cn'] ?? ''));
$icp_en = trim((string) ($icp['text_en'] ?? ''));
$icp_url = esc_url((string) ($icp['url'] ?? ''));
if ($icp_cn === '') {
$icp_cn = $icp_en;
}
if ($icp_en === '') {
$icp_en = $icp_cn;
}
if ($icp_cn !== '') :
?>
<?php if ($icp_url !== '') : ?><a href="<?php echo $icp_url; ?>" target="_blank" rel="noopener noreferrer" data-cn="<?php echo esc_attr($icp_cn); ?>" data-en="<?php echo esc_attr($icp_en); ?>"></a><?php else : ?><span data-cn="<?php echo esc_attr($icp_cn); ?>" data-en="<?php echo esc_attr($icp_en); ?>"></span><?php endif; ?>
<?php endif; ?>
<?php
$copyright = (array) ($site_content['footer_copyright'] ?? array());
$copyright_cn = trim((string) ($copyright['text_cn'] ?? ''));
$copyright_en = trim((string) ($copyright['text_en'] ?? ''));
if ($copyright_cn === '') {
$copyright_cn = $copyright_en;
}
if ($copyright_en === '') {
$copyright_en = $copyright_cn;
}
if ($copyright_cn !== '') :
?>
<p>&copy; <span data-cn="<?php echo esc_attr(wp_date('Y') . ' ' . $copyright_cn); ?>" data-en="<?php echo esc_attr(wp_date('Y') . ' ' . $copyright_en); ?>"></span></p>
<?php endif; ?>
</div>
</div>
</footer>
+367
View File
@@ -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 '<p>' . esc_html__('管理页脚内容和首页“服务提供”模块。留空的项目不会在前台显示。', 'itstudio') . '</p>';
},
'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 '<p class="description">' . esc_html__('最多 8 条,每条支持中英文名称和链接。', 'itstudio') . '</p>';
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 '<p class="description">' . esc_html__('最多 4 条,每条支持中英文文字和链接;链接可填写 mailto: 地址。', 'itstudio') . '</p>';
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 '<div style="display:grid;grid-template-columns:1fr 1fr 2fr;gap:8px;margin:0 0 8px;max-width:900px;">';
printf('<input type="text" class="regular-text" name="%s[title_cn]" value="%s" placeholder="%s">', esc_attr($base), esc_attr($title_cn), esc_attr__('中文名称', 'itstudio'));
printf('<input type="text" class="regular-text" name="%s[title_en]" value="%s" placeholder="%s">', esc_attr($base), esc_attr($title_en), esc_attr__('English label', 'itstudio'));
printf('<input type="url" class="regular-text" name="%s[url]" value="%s" placeholder="https://example.com">', esc_attr($base), esc_attr($url));
echo '</div>';
}
function itstudio_render_footer_addresses_field() {
$rows = itstudio_site_content_admin_rows('footer_addresses', 2);
echo '<p class="description">' . esc_html__('最多 2 条,每条支持中英文地址。', 'itstudio') . '</p>';
foreach ($rows as $index => $row) {
$base = 'itstudio_site_content_settings[footer_addresses][' . $index . ']';
printf('<div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;margin:0 0 8px;max-width:900px;"><textarea class="large-text" rows="2" name="%s[text_cn]" placeholder="%s">%s</textarea><textarea class="large-text" rows="2" name="%s[text_en]" placeholder="%s">%s</textarea></div>', 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 '<p><strong>' . esc_html__('备案信息', 'itstudio') . '</strong></p>';
printf('<div style="display:grid;grid-template-columns:1fr 1fr 2fr;gap:8px;margin:0 0 14px;max-width:900px;"><input type="text" class="regular-text" name="itstudio_site_content_settings[footer_icp][text_cn]" value="%s" placeholder="%s"><input type="text" class="regular-text" name="itstudio_site_content_settings[footer_icp][text_en]" value="%s" placeholder="%s"><input type="url" class="regular-text" name="itstudio_site_content_settings[footer_icp][url]" value="%s" placeholder="https://beian.miit.gov.cn/"></div>', esc_attr($icp['text_cn'] ?? ''), esc_attr__('中文备案信息', 'itstudio'), esc_attr($icp['text_en'] ?? ''), esc_attr__('English filing text', 'itstudio'), esc_attr($icp['url'] ?? ''));
echo '<p><strong>' . esc_html__('版权信息', 'itstudio') . '</strong></p>';
printf('<div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;max-width:900px;"><input type="text" class="regular-text" name="itstudio_site_content_settings[footer_copyright][text_cn]" value="%s" placeholder="%s"><input type="text" class="regular-text" name="itstudio_site_content_settings[footer_copyright][text_en]" value="%s" placeholder="%s"></div><p class="description">%s</p>', 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 '<p class="description">' . esc_html__('最多 8 条。设置中英文名称并从媒体库选择图像,支持 PNG、JPG、WebP 和 SVG。', 'itstudio') . '</p>';
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 '<div class="itstudio-service-setting-row" style="display:grid;grid-template-columns:1fr 1fr 180px;gap:8px;align-items:center;margin:0 0 12px;max-width:900px;">';
printf('<input type="text" class="regular-text" name="%s[name_cn]" value="%s" placeholder="%s">', esc_attr($base), esc_attr($row['name_cn'] ?? ''), esc_attr__('中文名称', 'itstudio'));
printf('<input type="text" class="regular-text" name="%s[name_en]" value="%s" placeholder="%s">', esc_attr($base), esc_attr($row['name_en'] ?? ''), esc_attr__('English name', 'itstudio'));
echo '<div>';
printf('<input type="hidden" class="itstudio-service-image-id" id="itstudio-service-image-%d" name="%s[image_id]" value="%d">', $index, esc_attr($base), $image_id);
printf('<button type="button" class="button itstudio-select-service-image" data-target="itstudio-service-image-%d" data-preview="itstudio-service-preview-%d">%s</button> ', $index, $index, esc_html__('选择图像', 'itstudio'));
printf('<button type="button" class="button-link-delete itstudio-clear-service-image" data-target="itstudio-service-image-%d" data-preview="itstudio-service-preview-%d">%s</button>', $index, $index, esc_html__('清除', 'itstudio'));
printf('<span id="itstudio-service-preview-%d" style="display:block;margin-top:6px;min-height:24px;">%s</span>', $index, $image_url ? '<img src="' . esc_url($image_url) . '" alt="" style="width:42px;height:42px;object-fit:contain;">' : '');
echo '</div></div>';
}
}
function itstudio_render_site_content_page() {
if (!current_user_can('manage_options')) {
return;
}
?>
<div class="wrap">
<h1><?php esc_html_e('站点内容设置', 'itstudio'); ?></h1>
<form action="options.php" method="post">
<?php
settings_fields('itstudio_site_content');
do_settings_sections('itstudio-site-content');
submit_button(__('保存设置', 'itstudio'));
?>
</form>
</div>
<?php
}
function itstudio_site_content_admin_assets($hook_suffix) {
if ($hook_suffix !== 'appearance_page_itstudio-site-content') {
return;
}
wp_enqueue_media();
}
add_action('admin_enqueue_scripts', 'itstudio_site_content_admin_assets');
function itstudio_site_content_admin_media_script() {
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
if (!$screen || $screen->id !== 'appearance_page_itstudio-site-content') {
return;
}
?>
<script>
(function () {
var frame;
document.addEventListener('click', function (event) {
var selectButton = event.target.closest('.itstudio-select-service-image');
var clearButton = event.target.closest('.itstudio-clear-service-image');
if (clearButton) {
var clearTarget = document.getElementById(clearButton.dataset.target);
var clearPreview = document.getElementById(clearButton.dataset.preview);
if (clearTarget) clearTarget.value = '';
if (clearPreview) clearPreview.innerHTML = '';
return;
}
if (!selectButton || typeof wp === 'undefined' || !wp.media) return;
var target = document.getElementById(selectButton.dataset.target);
var preview = document.getElementById(selectButton.dataset.preview);
frame = wp.media({
title: '<?php echo esc_js(__('选择服务图像', 'itstudio')); ?>',
button: { text: '<?php echo esc_js(__('使用此图像', 'itstudio')); ?>' },
library: { type: 'image' },
multiple: false
});
frame.on('select', function () {
var attachment = frame.state().get('selection').first().toJSON();
if (target) target.value = attachment.id || '';
if (preview) preview.innerHTML = attachment.url ? '<img src="' + attachment.url.replace(/&/g, '&amp;').replace(/"/g, '&quot;') + '" alt="" style="width:42px;height:42px;object-fit:contain;">' : '';
});
frame.open();
});
}());
</script>
<?php
}
add_action('admin_footer', 'itstudio_site_content_admin_media_script');
function itstudio_allow_admin_svg_uploads($mimes) {
if (current_user_can('manage_options')) {
$mimes['svg'] = 'image/svg+xml';
}
return $mimes;
}
add_filter('upload_mimes', 'itstudio_allow_admin_svg_uploads');
function itstudio_allow_admin_svg_filetype($data, $file, $filename, $mimes) {
if (current_user_can('manage_options') && strtolower(pathinfo($filename, PATHINFO_EXTENSION)) === 'svg') {
$data['ext'] = 'svg';
$data['type'] = 'image/svg+xml';
}
return $data;
}
add_filter('wp_check_filetype_and_ext', 'itstudio_allow_admin_svg_filetype', 10, 4);
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);
add_filter('comments_array', '__return_empty_array', 10, 2);
+29 -109
View File
@@ -2,6 +2,7 @@
<main class="site-main home-landing">
<?php
$site_content = itstudio_get_site_content_settings();
$announcement_archive_url = get_post_type_archive_link('announcement');
if (!$announcement_archive_url) {
$announcement_archive_url = home_url('/announcements');
@@ -28,116 +29,35 @@
<div class="services-provided">
<h2 data-cn="@ 服务提供" data-en="@ Services"></h2>
<div class="services-grid-box">
<div class="service-item service-resources">
<div class="service-icon">
<svg class="service-symbol" viewBox="0 0 72 72" fill="none" aria-hidden="true">
<circle class="svc-soft" cx="36" cy="36" r="24" />
<path class="svc-stroke" d="M17 24h14l4 5h20a4 4 0 0 1 4 4v22a4 4 0 0 1-4 4H17a4 4 0 0 1-4-4V28a4 4 0 0 1 4-4z" />
<rect class="svc-soft-strong" x="23" y="33" width="26" height="17" rx="2.6" />
<path class="svc-accent" d="M28 38h16M28 43h12M28 48h9" />
<path class="svc-muted" d="M51 35v13M51 48l3-3M51 48l-3-3" />
</svg>
<?php foreach (array_slice((array) ($site_content['homepage_services'] ?? array()), 0, 8) as $service) : ?>
<?php
$name_cn = trim((string) ($service['name_cn'] ?? ''));
$name_en = trim((string) ($service['name_en'] ?? ''));
if ($name_cn === '' && $name_en === '') {
continue;
}
if ($name_cn === '') {
$name_cn = $name_en;
}
if ($name_en === '') {
$name_en = $name_cn;
}
$image_id = absint($service['image_id'] ?? 0);
$image_url = $image_id > 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';
}
?>
<div class="service-item">
<div class="service-icon">
<img class="service-image" src="<?php echo esc_url($image_url); ?>" alt="" aria-hidden="true">
</div>
<span data-cn="<?php echo esc_attr($name_cn); ?>" data-en="<?php echo esc_attr($name_en); ?>"></span>
</div>
<span data-cn="资源站" data-en="Resources"></span>
</div>
<div class="service-item service-mirror">
<div class="service-icon">
<svg class="service-symbol" viewBox="0 0 72 72" fill="none" aria-hidden="true">
<circle class="svc-soft" cx="36" cy="36" r="24" />
<circle class="svc-stroke" cx="36" cy="36" r="17" />
<path class="svc-muted" d="M19 36h34M36 19c5 4.7 7.8 10.5 7.8 17S41 48.3 36 53M36 19c-5 4.7-7.8 10.5-7.8 17S31 48.3 36 53" />
<path class="svc-accent" d="M50 29l7 7-7 7" />
<path class="svc-accent" d="M57 36H45" />
<path class="svc-accent" d="M22 43l-7-7 7-7" />
<path class="svc-accent" d="M15 36h12" />
</svg>
</div>
<span data-cn="校内镜像站" data-en="Mirror Site"></span>
</div>
<div class="service-item service-git">
<div class="service-icon">
<svg class="service-symbol" viewBox="0 0 72 72" fill="none" aria-hidden="true">
<circle class="svc-soft" cx="36" cy="36" r="24" />
<rect class="svc-stroke" x="12" y="19" width="30" height="30" rx="4" />
<path class="svc-muted" d="M17 27h20M17 33h14" />
<circle class="svc-dot" cx="49" cy="24" r="3" />
<circle class="svc-dot" cx="49" cy="37" r="3" />
<circle class="svc-dot" cx="56" cy="47" r="3" />
<path class="svc-accent" d="M41 24h8" />
<path class="svc-accent" d="M49 24v13" />
<path class="svc-accent" d="M49 37c4 0 7 3 7 7" />
</svg>
</div>
<span data-cn="代码托管" data-en="Git Hosting"></span>
</div>
<div class="service-item service-minecraft">
<div class="service-icon">
<svg class="service-symbol" viewBox="0 0 72 72" fill="none" aria-hidden="true">
<circle class="svc-soft" cx="36" cy="36" r="24" />
<path class="svc-stroke" d="M36 15l20 11v23L36 60 16 49V26l20-11z" />
<path class="svc-muted" d="M16 26l20 11 20-11M36 60V37" />
<path class="svc-accent" d="M20 23h32" />
<rect class="svc-soft-strong" x="24" y="40" width="6" height="6" rx="1.2" />
<rect class="svc-soft-strong" x="34" y="43" width="5" height="5" rx="1.1" />
<rect class="svc-dot" x="43" y="39" width="6" height="6" rx="1.2" />
</svg>
</div>
<span data-cn="Minecraft服务器" data-en="Minecraft Server"></span>
</div>
<div class="service-item service-forum">
<div class="service-icon">
<svg class="service-symbol" viewBox="0 0 72 72" fill="none" aria-hidden="true">
<circle class="svc-soft" cx="36" cy="36" r="24" />
<path class="svc-stroke" d="M11 28a6 6 0 0 1 6-6h22a6 6 0 0 1 6 6v13a6 6 0 0 1-6 6H28l-8 7v-7h-3a6 6 0 0 1-6-6V28z" />
<path class="svc-accent" d="M36 19a6 6 0 0 1 6-6h13a6 6 0 0 1 6 6v9a6 6 0 0 1-6 6h-5l-4 4v-4h-4a6 6 0 0 1-6-6v-9z" />
<circle class="svc-dot" cx="24" cy="35" r="1.8" />
<circle class="svc-dot" cx="31" cy="35" r="1.8" />
<circle class="svc-dot" cx="46" cy="24" r="1.7" />
<circle class="svc-dot" cx="52" cy="24" r="1.7" />
</svg>
</div>
<span data-cn="OUC论坛" data-en="OUC Forum"></span>
</div>
<div class="service-item service-repair">
<div class="service-icon">
<svg class="service-symbol" viewBox="0 0 72 72" fill="none" aria-hidden="true">
<circle class="svc-soft" cx="36" cy="36" r="24" />
<rect class="svc-stroke" x="11" y="18" width="37" height="25" rx="4" />
<path class="svc-muted" d="M29.5 43v6M22 49h15" />
<path class="svc-accent" d="M38 24.5a4.7 4.7 0 0 0-6.5 6.6l-7.2 7.2 3.4 3.4 7.2-7.2a4.7 4.7 0 0 0 6.6-6.5l-3 3-2.6-2.6 2.1-3z" />
<path class="svc-accent" d="M50 19l10 10" />
<circle class="svc-dot" cx="55" cy="24" r="2" />
</svg>
</div>
<span data-cn="电脑维修" data-en="PC Repair"></span>
</div>
<div class="service-item service-workshop">
<div class="service-icon">
<svg class="service-symbol" viewBox="0 0 72 72" fill="none" aria-hidden="true">
<circle class="svc-soft" cx="36" cy="36" r="24" />
<rect class="svc-stroke" x="12" y="17" width="48" height="36" rx="5" />
<path class="svc-muted" d="M12 30h48M24 12v10M48 12v10" />
<rect class="svc-soft-strong" x="24" y="36" width="24" height="13" rx="3" />
<path class="svc-accent" d="M29 42l4 4 9-9" />
<circle class="svc-dot" cx="22" cy="24" r="1.8" />
<circle class="svc-dot" cx="30" cy="24" r="1.8" />
</svg>
</div>
<span data-cn="五八工坊预约" data-en="Workshop Booking"></span>
</div>
<div class="service-item service-campus">
<div class="service-icon">
<svg class="service-symbol" viewBox="0 0 72 72" fill="none" aria-hidden="true">
<circle class="svc-soft" cx="36" cy="36" r="24" />
<path class="svc-stroke" d="M36 14l18 8v14c0 12-7 20-18 25-11-5-18-13-18-25V22l18-8z" />
<path class="svc-muted" d="M36 24c-4.5 0-8 3.5-8 8 0 5.5 8 13 8 13s8-7.5 8-13c0-4.5-3.5-8-8-8z" />
<circle class="svc-soft-strong" cx="36" cy="32" r="3.2" />
<circle class="svc-soft-strong" cx="52" cy="22" r="5.2" />
<path class="svc-accent" d="M49.5 22H54.5M52 19.5v5" />
</svg>
</div>
<span data-cn="OUC便民服务" data-en="OUC Services"></span>
</div>
<?php endforeach; ?>
</div>
</div>
</div>