Files
YearlyData/Plugin.php

155 lines
5.1 KiB
PHP
Raw Normal View History

2026-02-23 21:11:30 +08:00
<?php
namespace TypechoPlugin\YearlyData;
use Typecho\Plugin\PluginInterface;
use Typecho\Widget\Helper\Form;
use Typecho\Widget\Helper\Form\Element\Text;
use Typecho\Widget\Helper\Form\Element\Radio;
use Widget\Options;
use Utils\Helper;
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
/**
* 年度数据
*
* @package YearlyData
* @author 石头厝
* @version 1.2.0
* @link https://www.shitoucuo.com/
*/
class Plugin implements PluginInterface
{
/**
* 插件版本号
*/
const VERSION = '1.2.0';
/**
* 激活插件方法
*/
public static function activate()
{
// 添加后台菜单1=控制台)
Helper::addPanel(3, 'YearlyData/Panel.php', '年度数据', '年度数据', 'administrator');
return _t('插件已激活,可在控制台菜单中找到"年度数据"入口');
}
/**
* 禁用插件方法
*/
public static function deactivate()
{
// 移除后台菜单
Helper::removePanel(3, 'YearlyData/Panel.php');
return _t('插件已禁用');
}
/**
* 获取插件配置面板
*/
public static function config(Form $form)
{
// 版本信息提示
/** echo '<div style="padding: 15px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 8px; margin-bottom: 20px; color: #fff;">';
echo '<div style="font-size: 18px; font-weight: bold; margin-bottom: 10px;">YearlyData 年度数据统计 v' . self::VERSION . '</div>';
echo '<div style="margin-bottom: 10px;">新增功能:年度目标设置与进度追踪</div>';
echo '<div style="font-size: 14px; opacity: 0.9;">请在左侧菜单「控制台 → 年度数据」中查看统计数据</div>';
echo '</div>';**/
// 默认显示条数
$topLimit = new Text('topLimit', null, '10',
_t('排行榜显示条数'),
_t('设置排行榜默认显示的条目数量'));
$form->addInput($topLimit);
// 默认年份
$defaultYear = new Text('defaultYear', null, date('Y'),
_t('默认统计年份'),
_t('设置默认统计的年份,留空则为当前年份'));
$form->addInput($defaultYear);
// 是否统计草稿
$includeDraft = new Radio('includeDraft',
['0' => _t('否'), '1' => _t('是')],
'0',
_t('是否统计草稿'),
_t('选择是否将草稿文章纳入统计'));
$form->addInput($includeDraft);
// 图表主题色
$chartColor = new Text('chartColor', null, '#667eea',
_t('图表主题色'),
_t('设置图表的主题颜色,使用十六进制颜色值'));
$form->addInput($chartColor);
// 年度目标设置标题
echo '<div style="padding: 15px; background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); border-radius: 8px; margin: 20px 0; color: #fff;">';
echo '<div style="font-size: 16px; font-weight: bold; margin-bottom: 10px;">' . date('Y') . '年度目标设置</div>';
echo '<div style="font-size: 14px; opacity: 0.9;">设置' . date('Y') . '年度的数据目标值,将在统计面板中显示进度条</div>';
echo '<div style="font-size: 12px; opacity: 0.8; margin-top: 5px;">提示:每年的目标需要单独设置,请根据年度更新目标值</div>';
echo '</div>';
// 年度总文章数目标
$targetPosts = new Text('targetPosts', null, '400',
_t('年度文章数目标'),
_t('设置' . date('Y') . '年度文章发布目标数量0表示不设置'));
$form->addInput($targetPosts);
// 年度总评论数目标
$targetComments = new Text('targetComments', null, '5000',
_t('年度评论数目标'),
_t('设置' . date('Y') . '年度评论数量目标0表示不设置'));
$form->addInput($targetComments);
// 年度总图片数目标
$targetImages = new Text('targetImages', null, '10000',
_t('年度图片数目标'),
_t('设置' . date('Y') . '年度图片上传目标数量0表示不设置'));
$form->addInput($targetImages);
// 年度总字数目标
$targetWords = new Text('targetWords', null, '2400000',
_t('年度总字数目标'),
_t('设置' . date('Y') . '年度文章总字数目标单位0表示不设置'));
$form->addInput($targetWords);
}
/**
* 个人用户的配置面板
*/
public static function personalConfig(Form $form)
{
// 暂无个人配置
}
/**
* 获取插件配置
*/
public static function getConfig($key = null)
{
try {
$config = Options::alloc()->plugin('YearlyData');
if ($key !== null) {
return isset($config->$key) ? $config->$key : null;
}
return $config;
} catch (\Exception $e) {
return null;
}
}
/**
* 获取插件版本
*/
public static function getVersion()
{
return self::VERSION;
}
}