Initial commit
Some checks failed
定时更新GitHub源插件 / 自动更新GitHub插件 (push) Has been cancelled

This commit is contained in:
chorblack
2026-03-07 11:19:25 +08:00
commit e75f275ef4
4484 changed files with 645480 additions and 0 deletions

BIN
Soso/404.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

181
Soso/Plugin.php Normal file
View File

@@ -0,0 +1,181 @@
<?php
/**
* 搜索增强插件,支持typecho1.1及以上版本,插件开源地址https://github.com/jrotty/soso
*
* @package Soso
* @author 泽泽社长
* @version 1.2.2
* @link http://zezeshe.com/
*/
class Soso_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Typecho_Plugin::factory('Widget_Archive')->search = array('Soso_Plugin', 'soso');
return _t('插件已激活,现在可以对插件进行设置!');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form){
$Somo = new Typecho_Widget_Helper_Form_Element_Radio('Somo',array('1' => _t('常规模式'),'2' => _t('仅搜索标题')),'1',_t('搜索模式'),_t(""));
$form->addInput($Somo);
$sid = new Typecho_Widget_Helper_Form_Element_Text('sid', NULL, NULL, _t('搜索结果不显示的分类'), _t('多个请用英文逗号隔开'));
$form->addInput($sid);
$tuozhan = new Typecho_Widget_Helper_Form_Element_Checkbox('tuozhan',
array(
'pinlv' => _t('勾选该项开启搜索频率限制,开启后请配置下方设置'),
),
array(), _t('拓展设置'), _t(''));
$form->addInput($tuozhan->multiMode());
$count = new Typecho_Widget_Helper_Form_Element_Text('count', NULL, '1', _t('限制搜索次数'), _t(''));
$form->addInput($count->addRule('isInteger', '请填纯数字次数'));
$time = new Typecho_Widget_Helper_Form_Element_Text('time', NULL, '60', _t('阻止时间(以秒为单位)'), _t(''));
$form->addInput($time->addRule('isInteger', '请填正确秒数'));
$txt = new Typecho_Widget_Helper_Form_Element_Text('txt', NULL, '一分钟只能搜索一次,请稍后再试!', _t('被限制后的显示提示'), _t(''));
$form->addInput($txt);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 插件实现方法
*
* @access public
* @return void
*/
/**
* 插件实现方法
*
* @access public
* @return void
*/
public static function soso($keywords, $obj) {
$count=intval(Typecho_Widget::widget('Widget_Options')->plugin('Soso')->count);
$time=Typecho_Widget::widget('Widget_Options')->plugin('Soso')->time;
$txt=Typecho_Widget::widget('Widget_Options')->plugin('Soso')->txt;
$Somo = Typecho_Widget::widget('Widget_Options')->plugin('Soso')->Somo;//获取设置参数
if(empty($count)){$count=1;}
if(empty($time)){$time=60;}
if(empty($txt)){$txt=$time."秒内只能搜索".$count."次,请稍后再试!";}
$cat=intval($obj->request->get('cat'));
$searchQuery = '%' . str_replace(' ', '%', $keywords) . '%';
if (!empty(Typecho_Widget::widget('Widget_Options')->plugin('Soso')->tuozhan) && in_array('pinlv', Typecho_Widget::widget('Widget_Options')->plugin('Soso')->tuozhan)){
session_start();
$ip=self::get_the_user_ip();//获取请求者ip
if(!empty($ip)){
if(!empty($_SESSION[$ip])&&empty($page)){
$timeout=time()-$_SESSION[$ip];//获取两次请求的时间差
if($timeout<$time){//如果时间差达到被限制的时间
if($_SESSION['count']<=$count){//如果请求次数未超过规定次数
$_SESSION['count']++;//请求次数+1
include('search.php');
}else{
include('theme.php');
exit;//否则就发出限制提示
}
}
else{//如果搜索间隔超过限制就允许正常搜索
$_SESSION['count']=1;//请求次数重置
$_SESSION[$ip]=time();
$_SESSION['count']++;//请求次数+1
include('search.php');
}
}else{//如果ip为第一次搜索或者处于搜索页面翻页状态就照常搜索
if(empty($page)){//翻页时不重置时间,不减少次数
$_SESSION[$ip]=time();
$_SESSION['count']=1;//请求次数重置
}
include('search.php');
}
}
else{
$txt= 'IP读取失败请关闭隐藏IP的相关工具后再次进行搜索';
include('theme.php');
exit;
}
}
else{
include('search.php');
}
}
private static function get_the_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
}

19
Soso/README.md Normal file
View File

@@ -0,0 +1,19 @@
# soso
typecho程序的搜索增强插件
## 功能介绍
搜索模式:有常规搜索和仅搜索文章标题两种模式。
搜索过滤:可以设置一些分类,让其不被搜索到。
搜索频率限制可以设定ip搜索频率限制
## 使用说明
下载后将soso文件夹传到typecho目录下然后启动插件打开插件设置根据文字提示设置即可。
## 插件升级操作说明
禁用旧版插件,删除旧版插件文件夹,然后上传最新版插件,启动插件设置插件即可
## 高级玩法
详见https://zezeshe.com/archives/typecho-search-category.html

35
Soso/search.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
$po = $obj->select()->join('table.relationships','table.relationships.cid = table.contents.cid','right')->join('table.metas','table.relationships.mid = table.metas.mid','right')->where('table.metas.type=?','category')
->where("table.contents.password IS NULL OR table.contents.password = ''")
->where('table.contents.status = ?', 'publish')
->where('table.contents.title LIKE ? OR table.contents.text LIKE ?', $searchQuery, $searchQuery)
->where('table.contents.type = ?', 'post')->group('cid');
//定制功能用来根据分类id搜索内容需模板代码配合才会启用
if($cat>0){
$po = $po->where('table.relationships.mid = ? OR table.metas.parent = ?',$cat,$cat);
}
//常规搜索
if($Somo==2){
$po = $po->where('table.contents.title LIKE ?', $searchQuery);//只允许搜索文章标题
}
$sid = Typecho_Widget::widget('Widget_Options')->plugin('Soso')->sid;
if(!$sid){}else{
$sid = explode(',', $sid);
$sid = array_unique($sid); //去除重复值
foreach ($sid as $k => $v) {
$po = $po->where('table.relationships.mid != '.intval($v));//确保每个值都是数字
}
}
$se = clone $po;
$obj->setCountSql($se);
$page=$obj->request->get('page');
$po = $po->order('table.contents.created', Typecho_Db::SORT_DESC)
->page($page, $obj->parameter->pageSize);
$obj->query($po);
return $keywords;
?>

18
Soso/theme.php Normal file
View File

@@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>限制提醒</title>
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<div class="box">
<div class='newContent'> <p><br/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p> <p style='text-align:center;'><img src='<?php echo Helper::options()->pluginUrl.'/Soso/404.png'; ?>' alt=''></img></p> <div style='text-align:center; font-size:16px; line-height:30px; color:#333333;'><?php echo $txt; ?></div> <a href='<?php echo Helper::options()->rootUrl; ?>' style='text-align:center; color:#333; font-size:13px; text-decoration:none; width:100px; height:32px; line-height:32px; border:1px solid #E3E2E8; display:block; margin:30px auto;'>返回首页</a> <p><br/> </p></div>
</div>
</body>
</html>