Skip to content

Commit

Permalink
feat: 👔 改进小程序分类使用的自定义字段
Browse files Browse the repository at this point in the history
  • Loading branch information
fordes123 committed Oct 17, 2024
1 parent fa39577 commit ab6a1f9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 179 deletions.
64 changes: 29 additions & 35 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,56 +136,27 @@ function themeFields($layout)
new Typecho_Widget_Helper_Form_Element_Radio(
'navigation',
array(
2 => _t('小程序导航'),
0 => _t('站内文章'),
1 => _t('网址导航'),
0 => _t('普通文章')
2 => _t('微信小程序'),
),
1,
_t('文章类型'),
_t("普通文章: 点击会前往详情页; 网址导航: 点击图标前往详情,点击其他位置直接跳转至对应url")
_t("普通文章: 点击会前往文章页<br/>• 网址导航: 点击图标前往详情,点击其他位置直接跳转至对应url<br/>• 小程序: 点击往详情页")
)
);
$layout->addItem(
new Typecho_Widget_Helper_Form_Element_Text('url', NULL, NULL, _t('跳转链接'), _t('请输入跳转URL,小程序不填'))
new Typecho_Widget_Helper_Form_Element_Text('url', NULL, NULL, _t('跳转地址'), _t('• 普通文章: 此字段留空即可<br/>• 网址导航: 可访问的URL<br/>• 小程序: 二维码图片URL'))
);
$layout->addItem(
new Typecho_Widget_Helper_Form_Element_Text('text', NULL, NULL, _t('导航描述'), _t('请输入导航描述'))
new Typecho_Widget_Helper_Form_Element_Text('text', NULL, NULL, _t('简单介绍'), _t('简短描述即可,将展示于首页和详情页开头<br/>(其他内容应记录在正文中)'))
);
$layout->addItem(
new Typecho_Widget_Helper_Form_Element_Text('logo', NULL, NULL, _t('链接logo'), _t('请输入Logo URL链接,网址加favicon.ico就是图标,默认是网站logo')));
$layout->addItem(
new Typecho_Widget_Helper_Form_Element_Text('qrcode', NULL, NULL, _t('小程序二维码'), _t('请输入小程序二维码链接!'))
);
$layout->addItem(
new Typecho_Widget_Helper_Form_Element_Text('screenshot', NULL, NULL, _t('功能预览'), _t('请输入功能预览链接!'))
new Typecho_Widget_Helper_Form_Element_Text('logo', NULL, NULL, _t('图标URL'), _t('文章/网站/小程序的图标链接<br/>留空则自动从 <a href="https://favicon.im/" target="_blank">favicon.im</a> 获取(不支持小程序)'))
);
$layout->addItem(
new Typecho_Widget_Helper_Form_Element_Text('score', NULL, NULL, _t('评分'), _t('请输入评分,1.0~5.0分'))
);
$layout->addItem(
new Typecho_Widget_Helper_Form_Element_Radio(
'advertisement',
array(
1 => _t(''),
0 => _t('')
),
0, // 默认值为 0 (无广告)
_t('是否存在广告'),
_t("请选择是否有广告!")
)
);
$layout->addItem(
new Typecho_Widget_Helper_Form_Element_Radio(
'official',
array(
1 => _t(''),
0 => _t('')
),
0, // 默认值为 0 (非官方小程序)
_t('是否是官方小程序'),
_t("请选择是否为官方小程序!")
)
);
}

/**
Expand Down Expand Up @@ -321,4 +292,27 @@ function getSiteFavicon($posts) {
$logo = 'https://favicon.im/' . parse_url($url, PHP_URL_HOST);
}
return $logo;
}

function displayStars($score) {
$score = max(0, min(5, $score));

$fullStars = floor($score);
$halfStars = ($score - $fullStars) >= 0.5 ? 1 : 0;
$emptyStars = 5 - $fullStars - $halfStars;

$stars = '';
for ($i = 0; $i < $fullStars; $i++) {
$stars .= '<i class="fas fa-star" style="color: #FFD43B;"></i>';
}

if ($halfStars) {
$stars .= '<i class="fas fa-star-half-alt" style="color: #FFD43B;"></i>';
}

for ($i = 0; $i < $emptyStars; $i++) {
$stars .= '<i class="far fa-star" style="color: #FFD43B;"></i>';
}

return $stars;
}
110 changes: 0 additions & 110 deletions page-article.php

This file was deleted.

2 changes: 1 addition & 1 deletion page.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$this->need('page-article.php');
$this->need('post.php');
6 changes: 3 additions & 3 deletions post-modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body d-flex flex-column justify-content-center align-items-center gap-3">
<?php if ($this->fields->qrcode): ?>
<img src="<?php $this->fields->qrcode(); ?>" alt="二维码" class="img-fluid mt-3">
<?php else: ?>
<?php if ($this->fields->url): ?>
<img src="<?php $this->fields->url(); ?>" alt="二维码" class="img-fluid mt-3">
<?php elseif ($this->fields->logo): ?>
<img src="<?php $this->fields->logo(); ?>" alt="logo" class="img-fluid mt-3">
<?php endif; ?>
<p class="modal-title mb-3">小程序名称:<?php echo $this->title(); ?></p>
Expand Down
39 changes: 9 additions & 30 deletions post.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
error_log("post.php");
if (isset($_POST['agree'])) {
if ($_POST['agree'] == $this->cid) {
exit(agree($this->cid));
echo agree($this->cid);
exit;
}
exit('error');
exit;
}
$agree = $this->hidden ? array('agree' => 0, 'recording' => true) : agreeNum($this->cid);
$this->need('header.php');
$this->need('sidebar.php');
$this->need('topbar.php');
if ($this->fields->navigation == 2):
$this->need('post-modal.php');
endif;
?>


Expand Down Expand Up @@ -39,9 +43,9 @@
<?php endforeach; ?>
</div>
<div class="post-content">
<div class="post-excerpt"><i class="excerpt-icon"></i>
<div class="post-excerpt">
<?php if ($this->fields->text): ?>
<!-- 显示 链接描述 -->
<i class="excerpt-icon"></i>
<h4><?php echo $this->fields->text; ?></h4>
<?php endif; ?>
<?php if ($this->fields->score): ?>
Expand All @@ -51,36 +55,11 @@
<i class="text-light mx-2">•</i>
<?php echo $this->fields->score ?>
<i class="text-light mx-2">•</i>
<?php
$score = floatval($this->fields->score);
$totalStars = 5;
$fullStars = floor($score);
$partialScore = $score - $fullStars;
for ($i = 0; $i < $fullStars; $i++) {
echo '<i class="fas fa-star" style="color: #FFD43B;"></i>';
}
if ($partialScore > 0) {
echo '<i class="fas fa-star-half-alt" style="color: #FFD43B;"></i>';
$fullStars++;
}
for ($i = $fullStars; $i < $totalStars; $i++) {
echo '<i class="far fa-star" style="color: #FFD43B;"></i>';
}
?>
<?php echo displayStars($this->fields->score) ?>
</div>
<?php endif; ?>
</div>
<div class="text-wrap text-break fs-6 mx-3">
<?php if ($this->fields->screenshot): ?>
<!-- 显示 截图 -->
<div class="nav-image-container">
<img class="nav-thumbnail" src="<?php echo $this->fields->screenshot ?>" alt="<?php echo $this->title ?>" data-bs-toggle="modal" data-bs-target="#navModal">
</div>
<?php endif; ?>
<?php if ($this->fields->navigation !== 0): ?>
<h3><?php $this->title(); ?>-使用体验</h3>
<?php endif; ?>
<!-- 显示 文章 -->
<?php $this->content(); ?>
</div>
</div>
Expand Down

0 comments on commit ab6a1f9

Please sign in to comment.