Skip to content

Commit

Permalink
使用PHP_CodeSniffer使所有文件 PSR-12 化 (#231)
Browse files Browse the repository at this point in the history
Co-authored-by: BANKA2017 <[email protected]>
  • Loading branch information
n0099 and BANKA2017 authored Feb 26, 2023
1 parent 26c8612 commit dd29af3
Show file tree
Hide file tree
Showing 44 changed files with 1,603 additions and 1,555 deletions.
22 changes: 13 additions & 9 deletions lib/class.misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,19 +575,23 @@ public static function scanTiebaByPid($pid)
$o = option::get('tb_max');
$pn = 1;
$a = 0;
while (true){
while (true) {
//if (empty($bid)) break;
$rc = self::getTieba2($bduss, $stoken, $pn);//fetch forum list //default 200 per page
$rc = json_decode($rc,true);
if(!$rc) {break;}
$rc = json_decode($rc, true);
if (!$rc) {
break;
}
$ngf = isset($rc["data"]["like_forum"]["list"]) ? $rc["data"]["like_forum"]["list"] : [];
foreach ($ngf as $v){
if ($tb['c'] + $a >= $o && !empty($o) && !$isvip) break;
foreach ($ngf as $v) {
if ($tb['c'] + $a >= $o && !empty($o) && !$isvip) {
break;
}
$vn = addslashes(htmlspecialchars($v['forum_name']));
$ist = $m->once_fetch_array("SELECT COUNT(id) AS `c` FROM `".DB_NAME."`.`".DB_PREFIX.$table."` WHERE `pid` = {$pid} AND `tieba` = '{$vn}';");
if ($ist['c'] == 0){
$a ++;
$m->query("INSERT INTO `".DB_NAME."`.`".DB_PREFIX.$table."` (`pid`,`fid`, `uid`, `tieba`) VALUES ({$pid},'{$v['forum_id']}', {$uid}, '{$vn}');");
$ist = $m->once_fetch_array("SELECT COUNT(id) AS `c` FROM `" . DB_NAME . "`.`" . DB_PREFIX . $table . "` WHERE `pid` = {$pid} AND `tieba` = '{$vn}';");
if ($ist['c'] == 0) {
$a++;
$m->query("INSERT INTO `" . DB_NAME . "`.`" . DB_PREFIX . $table . "` (`pid`,`fid`, `uid`, `tieba`) VALUES ({$pid},'{$v['forum_id']}', {$uid}, '{$vn}');");
}
}
$pn++;
Expand Down
4 changes: 3 additions & 1 deletion plugins/ver4_ban/cron/dopost.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php if (!defined('SYSTEM_ROOT')) {
<?php

if (!defined('SYSTEM_ROOT')) {
die('Insufficient Permissions');
}
$id = option::get('ver4_ban_id');
Expand Down
15 changes: 10 additions & 5 deletions plugins/ver4_ban/ver4_ban.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php if (!defined('SYSTEM_ROOT')) {
<?php

if (!defined('SYSTEM_ROOT')) {
die('Insufficient Permissions');
}

Expand Down Expand Up @@ -51,7 +53,7 @@ function ver4_ban($pid, $portrait, $name, $name_show, $tieba, $reason, int $day
/*
* 执行封禁操作 客户端
* */
function ver4_ban_client ($pid, $portrait, $name, $tieba, $reason, int $day = 1)
function ver4_ban_client($pid, $portrait, $name, $tieba, $reason, int $day = 1)
{
$bduss = misc::getCookie($pid);
$r = empty($reason) ? '您因为违反吧规,已被吧务封禁,如有疑问请联系吧务!' : $reason;
Expand Down Expand Up @@ -106,13 +108,15 @@ function ver4_get_manager_web_backstage($pid, string $tieba_name)
}

//某个pid下帐号是否为吧务
function ver4_is_manager($pid, string $tieba_name): array {
function ver4_is_manager($pid, string $tieba_name): array
{
return [
"isManager" => (bool)preg_match('/<p class="forum_list_position">([^<]+)<\/p>/', ver4_get_manager_web_backstage($pid, $tieba_name), $managerType),
"managerType" => empty($managerType[1]) ? "" : $managerType[1],
];
}
function ver4_ban_get_userinfo_by_words ($word) :array {
function ver4_ban_get_userinfo_by_words($word): array
{
$getInfo = json_decode((new wcurl("https://tieba.baidu.com/mo/q/search/user?word={$word}", ['User-Agent: tieba/12.5.1']))->get(), true);
$userInfo = [];
if (isset($getInfo["data"]["exactMatch"]["id"])) {
Expand All @@ -139,7 +143,8 @@ function ver4_ban_get_userinfo_by_words ($word) :array {
}

//生成封禁列表
function ver4_ban_global_ban_list_generate (array $i, $m):array {
function ver4_ban_global_ban_list_generate(array $i, $m): array
{
$globalBanList = [];
foreach ($i["user"]["baidu"] as $userId => $userBaiduName) {
$globalBanList[$userId] = [
Expand Down
8 changes: 5 additions & 3 deletions plugins/ver4_ban/ver4_ban_callback.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php if (!defined('SYSTEM_ROOT')) {
<?php

if (!defined('SYSTEM_ROOT')) {
die('Insufficient Permissions');
}
/**
Expand Down Expand Up @@ -63,8 +65,8 @@ function callback_remove()
{
//在这里做点事
global $m;
$m->query("DROP TABLE IF EXISTS `".DB_PREFIX."ver4_ban_userset`");
$m->query("DROP TABLE IF EXISTS `".DB_PREFIX."ver4_ban_list`");
$m->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "ver4_ban_userset`");
$m->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "ver4_ban_list`");
}

/**
Expand Down
4 changes: 3 additions & 1 deletion plugins/ver4_ban/ver4_ban_desc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php if (!defined('SYSTEM_ROOT')) {
<?php

if (!defined('SYSTEM_ROOT')) {
die('Insufficient Permissions');
}
//没有标注必填的都是选填但是按照规范请保留该键只需将值留空即可
Expand Down
6 changes: 3 additions & 3 deletions plugins/ver4_ban/ver4_ban_setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<br>
<?php
if (isset($_GET['msg'])) {
echo '<div class="alert alert-success">'.htmlspecialchars($_GET['msg']).'</div>';
echo '<div class="alert alert-success">' . htmlspecialchars($_GET['msg']) . '</div>';
}
if (isset($_GET['save'])) {
option::set('ver4_ban_limit', $_POST['limit']);
option::set('ver4_ban_break_check', $_POST['break_check'] === 'on' ? '1' : '0');
redirect('index.php?mod=admin:setplug&plug=ver4_ban&msg='.urlencode('设置已保存成功!'));
redirect('index.php?mod=admin:setplug&plug=ver4_ban&msg=' . urlencode('设置已保存成功!'));
}
?>
<br>
Expand All @@ -20,7 +20,7 @@
<input type="text" class="form-control" name="limit" placeholder="此处填写用户最多可以添加多少条封禁" value="<?= option::get('ver4_ban_limit') ?>" required>
</div>
<br>
<label for="break-check">允许跳过权限检查</label> <input type="checkbox" id="break-check" name="break_check" <?= option::get('ver4_ban_break_check') === '1' ? 'checked': '' ?>>
<label for="break-check">允许跳过权限检查</label> <input type="checkbox" id="break-check" name="break_check" <?= option::get('ver4_ban_break_check') === '1' ? 'checked' : '' ?>>
<br>
<br>
<input type="submit" class="btn btn-primary" value="保存设置">
Expand Down
27 changes: 14 additions & 13 deletions plugins/ver4_ban/ver4_ban_show.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,52 +38,52 @@
$pid = isset($_POST['pid']) ? sqladds($_POST['pid']) : '';
$user = isset($_POST['user']) ? sqladds($_POST['user']) : '';
$tieba = isset($_POST['tieba']) ? sqladds($_POST['tieba']) : '';

//判定吧务权限
if (option::get('ver4_ban_break_check') === '0' && !ver4_is_manager($pid, $tieba)["isManager"]) {
$apiReturnArray["message"] = "您不是 {$tieba}吧 的吧务";
}

$rts = isset($_POST['rts']) && !empty($_POST['rts']) ? sqladds($_POST['rts']) : date('Y-m-d');
$rte = isset($_POST['rte']) ? sqladds($_POST['rte']) : '2026-12-31';

$sy = (int)substr($rts, 0, 4);//取得年份
$sm = (int)substr($rts, 5, 2);//取得月份
$sd = (int)substr($rts, 8, 2);//取得日期
$stime = mktime(0, 0, 0, $sm, $sd, $sy);

$ey = (int)substr($rte, 0, 4);//取得年份
$em = (int)substr($rte, 5, 2);//取得月份
$ed = (int)substr($rte, 8, 2);//取得日期
$etime = mktime(0, 0, 0, $em, $ed, $ey);

if (empty($pid) || empty($user) || empty($tieba)) {
$apiReturnArray["message"] = "信息不完整,添加失败";
break;
}

if ($stime > 1988150400 || $etime > 1988150400 || $stime < 0 || $etime < 0) {
$apiReturnArray["message"] = "开始或者结束时间格式不正确";
break;
}

if (date('Y-m-d', $stime) != $rts || date('Y-m-d', $etime) != $rte) {
$apiReturnArray["message"] = "开始或者结束时间格式不正确";
break;
}

if ($stime > $etime) {
$apiReturnArray["message"] = "开始时间不能大于结束时间";
break;
}

global $m;
$p = $m->fetch_array($m->query("SELECT * FROM `" . DB_NAME . "`.`" . DB_PREFIX . "baiduid` WHERE `id` = '{$pid}'"));
if ($p['uid'] != UID) {
$apiReturnArray["message"] = "你不能替他人添加帖子";
break;
}

$limit = option::get('ver4_ban_limit');
$t = $m->fetch_array($m->query("SELECT count(id) AS `c` FROM `" . DB_NAME . "`.`" . DB_PREFIX . "ver4_ban_list` WHERE `uid` = {$uid}"));
if ($t['c'] >= $limit) {
Expand Down Expand Up @@ -328,7 +328,7 @@
<ul id="myTabs" class="nav nav-tabs" role="tablist">
<?php
foreach ($globalBanList as $order => $list) {
echo '<li role="presentation" class="' . ($order === array_keys($globalBanList)[0] ? 'active' : '') . '"><a href="#b' . $order .'" role="tab" data-toggle="tab">' . $list['name'] . '</a></li>';
echo '<li role="presentation" class="' . ($order === array_keys($globalBanList)[0] ? 'active' : '') . '"><a href="#b' . $order . '" role="tab" data-toggle="tab">' . $list['name'] . '</a></li>';
}
?>
</ul>
Expand All @@ -338,7 +338,7 @@
foreach ($globalBanList as $order => $list) {?>
<div role="tabpanel" class="tab-pane fade <?= ($order === array_keys($globalBanList)[0] ? 'active in' : '') ?>" id="b<?= $order ?>">
<?php
if (count($list["list"]) === 0 ) {
if (count($list["list"]) === 0) {
echo '<div class="text-center">封禁列表为空</div>';
} else {
foreach ($list["list"] as $itemOrder => $item) { ?>
Expand Down Expand Up @@ -414,7 +414,8 @@ class="sr-only">Close</span></button>
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
<?php }} ?>
<?php }
} ?>
</div>
<?php } ?>
</div>
Expand Down
4 changes: 3 additions & 1 deletion plugins/ver4_lottery/cron/dopost.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php if (!defined('SYSTEM_ROOT')) {
<?php

if (!defined('SYSTEM_ROOT')) {
die('Insufficient Permissions');
}
global $m;
Expand Down
8 changes: 5 additions & 3 deletions plugins/ver4_lottery/ver4_lottery.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php if (!defined('SYSTEM_ROOT')) {
<?php

if (!defined('SYSTEM_ROOT')) {
die('Insufficient Permissions');
}

Expand All @@ -19,7 +21,7 @@ function getToken($pid)
{
$bduss = misc::getCookie($pid);
$tc = new wcurl('https://zhidao.baidu.com/shop/lottery');
$tc->addCookie('BDUSS='.$bduss);
$tc->addCookie('BDUSS=' . $bduss);
$re = $tc->get();
$token = textMiddle($re, '\'luckyToken\', \'', '\'');
return $token;
Expand All @@ -33,7 +35,7 @@ function lottery($pid, $token)
$head[] = 'Referer: https://zhidao.baidu.com/shop/lottery';
$head[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36';
$pl = new wcurl("https://zhidao.baidu.com/shop/submit/lottery?type=0&token={$token}&_={$nt}308", $head);
$pl->addCookie('BDUSS='.$bduss);
$pl->addCookie('BDUSS=' . $bduss);
$re = $pl->get();
$result = json_decode($re, true);
return $result;
Expand Down
8 changes: 5 additions & 3 deletions plugins/ver4_lottery/ver4_lottery_callback.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php if (!defined('SYSTEM_ROOT')) {
<?php

if (!defined('SYSTEM_ROOT')) {
die('Insufficient Permissions');
}
/**
Expand All @@ -8,7 +10,7 @@ function callback_install()
{
global $m;
$m->query("
CREATE TABLE IF NOT EXISTS `".DB_PREFIX."ver4_lottery_log` (
CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "ver4_lottery_log` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`uid` int(10) NOT NULL,
`pid` int(10) NOT NULL,
Expand Down Expand Up @@ -48,7 +50,7 @@ function callback_remove()
{
//在这里做点事
global $m;
$m->query("DROP TABLE IF EXISTS `".DB_PREFIX."ver4_lottery_log`");
$m->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "ver4_lottery_log`");
}

/**
Expand Down
4 changes: 3 additions & 1 deletion plugins/ver4_lottery/ver4_lottery_desc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php if (!defined('SYSTEM_ROOT')) {
<?php

if (!defined('SYSTEM_ROOT')) {
die('Insufficient Permissions');
}
//没有标注必填的都是选填但是按照规范请保留该键只需将值留空即可
Expand Down
Loading

0 comments on commit dd29af3

Please sign in to comment.